我使用ContentResolver获取歌曲列表:
ContentResolver cr = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor cur = cr.query(uri, null, selection, null, sortOrder);
int count = 0;
if(cur != null) {
count = cur.getCount();
if(count > 0) {
while(cur.moveToNext()) {
songs.add(cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.DATA)));
}
}
}
cur.close();
然后我尝试使用MediaPlayer播放列表中的第一首歌曲:
MediaPlayer player = new MediaPlayer();
try {
player.setDataSource(songs.get(0));
} catch (IOException e) {
e.printStackTrace();
}
player.start();
我收到错误:
12-09 16:08:12.662 135-554 /? D / FFMPEG:android源关闭
12-09 16:08:12.662 135-554 /? D / FFmpegExtractor:SniffFFMPEG失败了 嗅探这个来源
12-09 16:08:12.666 1324-1324 /? E / MediaPlayer:开始在状态2中调用
12-09 16:08:12.666 1324-1324 /? E / MediaPlayer:错误(-38,0)