android – 获得一首歌的流派

android – 获得一首歌的流派,第1张

概述我如何阅读与歌曲相关的流派?我可以读这首歌,但是如何抓住这首歌的流派,它存放在哪里? 谢谢! 检查此代码: public class MusicLibraryScanner { private static Cursor mediaCursor; private static Cursor genresCursor; private static String[] me 我如何阅读与歌曲相关的流派?我可以读这首歌,但是如何抓住这首歌的流派,它存放在哪里?

谢谢!

解决方法 检查此代码:
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 – 获得一首歌的流派所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1139205.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存