我正在尝试使用MediaStore提供程序播放获取到的播放列表。但是,当我尝试播放播放列表时,什么都不会发生。MediaPlayer能否播放播放列表(m3u文件),我需要设置播放的第一首曲目吗?
这是我的测试代码,位于onCreate()方法中:
Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
if(uri == null) {
Log.e("Uri = null");
}
String[] projection = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists.DATA };
Cursor c = managedQuery(uri, projection, null, null, null);
if(c == null) {
Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_error, Toast.LENGTH_LONG).show();
return;
}
if(!c.moveToFirst()) {
c.close();
Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_no_music, Toast.LENGTH_LONG).show();
return;
}
c.moveToFirst();
try {
MediaPlayer player = new MediaPlayer();
player.setDataSource(c.getString(2));
player.start();
} catch(Exception e) {
e.printStackTrace();
}
我已经打开了所有的音量流。
谢谢,
Kaloer