我正在开发一个简单的Android音频播放器。 我想列出相册在设备中。
我试过这个代码
String where = new String(); where = MediaStore.Audio.Media.IS_MUSIC + "=1"; private Cursor managedCursor; managedCursor = managedQuery( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ARTIST_ID }, where, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER ); ListAdapter adapter = new AlbumListAdapter( this, R.layout.albumlist_item, managedCursor, new String[] { MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST }, new int[] { R.id.text_album, R.id.text_artist } ); setListAdapter(adapter);但是这段代码列出了设备中的所有歌曲。
Android Media商店数据库的结构是什么?
任何人请帮助。
I am developing a simple audio player in android. I want to list the album's in the device.
I tried this code
String where = new String(); where = MediaStore.Audio.Media.IS_MUSIC + "=1"; private Cursor managedCursor; managedCursor = managedQuery( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ARTIST_ID }, where, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER ); ListAdapter adapter = new AlbumListAdapter( this, R.layout.albumlist_item, managedCursor, new String[] { MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST }, new int[] { R.id.text_album, R.id.text_artist } ); setListAdapter(adapter);But this code is listing the all the song's in the device.
What is the structure of the Android Media store DB.
Any one please help.
最满意答案
你应该像这样查询专辑
String[] projection = new String[] { Albums._ID, Albums.ALBUM, Albums.ARTIST, Albums.ALBUM_ART, Albums.NUMBER_OF_SONGS }; String selection = null; String[] selectionArgs = null; String sortOrder = Media.ALBUM + " ASC"; Cursor cursor = contentResolver.query(Albums.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, sortOrder);http://developer.android.com/reference/android/provider/MediaStore.Audio.Albums.html
艺术家,播放列表和流派都可以使用正确的EXTERNAL_CONTENT_URI和相应的投影以类似的方式进行查询。
希望这有助于...
You should query the Albums like this
String[] projection = new String[] { Albums._ID, Albums.ALBUM, Albums.ARTIST, Albums.ALBUM_ART, Albums.NUMBER_OF_SONGS }; String selection = null; String[] selectionArgs = null; String sortOrder = Media.ALBUM + " ASC"; Cursor cursor = contentResolver.query(Albums.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, sortOrder);http://developer.android.com/reference/android/provider/MediaStore.Audio.Albums.html
Artists, Playlists and Genres can all be queried in a similar way using the correct EXTERNAL_CONTENT_URI and the corresponding projection.
Hope that helps...
更多推荐
发布评论