我正在尝试制作一个基本的音乐应用程序,但是由于某种原因,我的getContentResolver似乎没有在模拟器上返回mp3。
代码如下:
columns = new String[] {
MediaStore.Audio.AudioColumns.ARTIST,
MediaStore.Audio.AudioColumns.TITLE,
MediaStore.Audio.AudioColumns.ALBUM,
MediaStore.Audio.AudioColumns.ALBUM_ID,
MediaStore.Audio.AudioColumns.IS_MUSIC
};
cursor = context.getContentResolver().query(
MediaStore.Audio.Media.INTERNAL_CONTENT_URI,
columns,
MediaStore.Audio.Media.IS_MUSIC + " = 1",
null,
null
);
现在,我将mp3文件夹拖到手机上,并将其移动到内部存储器的“音乐”文件夹中。他们在那里,他们有一个文件大小。当我遍历光标时,会得到以下列表:
<unknown>: KeypressSpacebar, ui, isMusic: 1
<unknown>: Lock, ui, isMusic: 1
<unknown>: Unlock, ui, isMusic: 1
(c) 2012 Android Open Source Project: Video Record, ui, isMusic: 1
(c) 2012 Android Open Source Project: Camera Shutter, ui, isMusic: 1
<unknown>: Effect_Tick, ui, isMusic: 1
<unknown>: camera_focus, ui, isMusic: 1
(c) 2012 Android Open Source Project: Video Stop, ui, isMusic: 1
<unknown>: Dock, ui, isMusic: 1
Copyright 2013 Android Open Source Project: KeypressInvalid, ui, isMusic: 1
<unknown>: Trusted, ui, isMusic: 1
<unknown>: KeypressStandard, ui, isMusic: 1
<unknown>: KeypressReturn, ui, isMusic: 1
<unknown>: Low Battery, ui, isMusic: 1
<unknown>: Undock, ui, isMusic: 1
<unknown>: KeypressDelete, ui, isMusic: 1
<unknown>: WirelessChargingStarted, ui, isMusic: 1
应该是artist: title, album, is_music
。
为什么不接我的mp3?我需要刷新吗?重新启动仿真器也没有任何区别。
编辑:我将文件移至外部存储,并切换了getContentResolver到那里,现在显示了文件。但是我不明白为什么它不会从内部显示?而且,为什么显示 的文件被列为Is_Music,它们肯定是UI?
Edit2:我像这样遍历光标:
if(cursor != null) {
while(cursor.moveToNext()) {
String artist = cursor.getString(0);
String title = cursor.getString(1);
String album = cursor.getString(2);
Log.d("MediaContent::", "getMusicFiles: " + artist + ": " + title + ", " + album + ", isMusic: " + String.valueOf(cursor.getInt(4)));
}
cursor.close();
}