Getting efficiently the Genres of the Audio files in the MediaStore

你离开我真会死。 提交于 2019-11-30 19:47:30

问题


I am trying to synchronize my own database for tracks and albums (that contains additional data). I have so far successfully pulled albums and tracks from the MediaStore.

What I cannot manage to do properly is to pull the Genres for the tracks. Could someone post some code? I'd like to avoid querying the database for each track, so if possible some code to load the association (Genre.id <-> Audio.id) would be great.

What I am struggling on is using the content provider to get the Genres.Members info.


回答1:


I'd take a look at how the excellent creators of ringdroid do this. http://ringdroid.googlecode.com/svn-history/r37/trunk/src/com/ringdroid/SongMetadataReader.java

They basically start by retrieving the genres names and ids and using those they can easily create a content_uri that retrieves only songs in the database that matches those genres. But if I were you I would check whether there is an "unknown" or "empty" genre or not for the files that contain no Genre name in their id3 tag




回答2:


So what I ended up doing is getting all audio files on the sd with a loader and following query:

        loader = new CursorLoader(mActivity, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
                new String[] {Audio.Media._ID, Audio.Media.DATA}, 
                null, null, null);

Then i check if they end with .mp3 and I then use jaudiotagger and read the ide3 tags for genre.



来源:https://stackoverflow.com/questions/4889242/getting-efficiently-the-genres-of-the-audio-files-in-the-mediastore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!