在我的应用中,我使用MediaStore
和ListAdaptor
以及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);
答案 0 :(得分: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);
答案 1 :(得分:-1)
请参阅THIS示例,该示例仅显示提供的文件扩展名列表。