在Android上市专辑(listing album in android)

编程入门 行业动态 更新时间:2024-10-21 09:23:16
在Android上市专辑(listing album in android)

我正在开发一个简单的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...

更多推荐

本文发布于:2023-08-01 04:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1352862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:专辑   Android   listing   android   album

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!