4

在我的应用程序中,我使用MediaStoreandListAdaptor和显示所有音频文件CursorLoader。但它显示所有音频文件(m4a、wav、ogg)。我只想显示 mp3 文件。我该怎么做?

String[] from = {MediaStore.MediaColumns.TITLE};
int[] to = {android.R.id.text1};

CursorLoader cursorLoader = new CursorLoader(this,sourceUri,null,null,null,MediaStore.Audio.Media.TITLE);
Cursor cursor = cursorLoader.loadInBackground();
startManagingCursor(cursor);
ListAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,from,to,CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(adapter);
4

2 回答 2

8

请尝试以下代码

ContentResolver cr = context.getContentResolver();

Uri uri = MediaStore.Files.getContentUri("external");

String[] projection = null;

String sortOrder = null;

String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";

String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("mp3"); 

String[] selectionArgsMp3 = new String[]{ mimeType };

Cursor allmp3Files = cr.query(uri, projection, selectionMimeType, selectionArgsmp3, sortOrder);
于 2013-02-18T11:53:48.637 回答
-1

请参阅示例,该示例仅显示提供的文件扩展名列表。

于 2013-02-18T13:17:58.427 回答