我正在制作一个音乐播放器应用,而且我的手机没有SD卡插槽,因此当我运行我的代码时,它会显示.ogg
个文件而不是歌曲。
我将Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
更改为
Uri uri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
但它只显示.ogg
但不显示歌曲。
如果我将Uri更改为
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
我收到以下错误 - setDataSource failed: status = 0x80000000
这是我的代码,
private void loadSongs() {
Uri uri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
Uri uriPath;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
Log.i("DATA111", url);
mediaMetadataRetrieve = new MediaMetadataRetriever();
mediaMetadataRetrieve.setDataSource());
art = mediaMetadataRetrieve.getEmbeddedPicture();
if (art != null) {
songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
}
SongInfo s = new SongInfo(name, artist, url, songImage);
_songs.add(s);
} while (cursor.moveToNext());
}
cursor.close();
songAdapter = new SongAdapter(MainActivity.this, _songs);
有人可以帮我找到解决这个问题的方法吗?