谢谢!
解决方法 检查此代码:public class MusiclibraryScanner { private static Cursor mediaCursor; private static Cursor genresCursor; private static String[] mediaProjection = { MediaStore.Audio.Media._ID,MediaStore.Audio.Media.ARTIST,MediaStore.Audio.Media.ALBUM,MediaStore.Audio.Media.Title }; private static String[] genresProjection = { MediaStore.Audio.Genres.name,MediaStore.Audio.Genres._ID }; public static voID getMusicFromStorage(Context context) { mediaCursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,mediaProjection,null,null); int artist_column_index = mediaCursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST); int album_column_index = mediaCursor .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM); int Title_column_index = mediaCursor .getColumnIndexOrThrow(MediaStore.Audio.Media.Title); int ID_column_index = mediaCursor .getColumnIndexOrThrow(MediaStore.Audio.Media._ID); if (mediaCursor.movetoFirst()) { do { String info = "Song " + mediaCursor.getString(Title_column_index) + " "; info += "from album " + mediaCursor.getString(album_column_index) + " "; info += "by " + mediaCursor.getString(artist_column_index) + ". "; int musicID = Integer.parseInt(mediaCursor.getString(ID_column_index)); Uri uri = MediaStore.Audio.Genres.getContentUriForAudioID("external",musicID); genresCursor = context.getContentResolver().query(uri,genresProjection,null); int genre_column_index = genresCursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.name); if (genresCursor.movetoFirst()) { info += "Genres: "; do { info += genresCursor.getString(genre_column_index) + " "; } while (genresCursor.movetoNext()); } Log.e("Audio scanner","Song info: " + info); } while (mediaCursor.movetoNext()); } }}总结
以上是内存溢出为你收集整理的android – 获得一首歌的流派全部内容,希望文章能够帮你解决android – 获得一首歌的流派所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)