gpt4 book ai didi

android - 获取歌曲的流派

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:56:59 24 4
gpt4 key购买 nike

我如何着手阅读歌曲相关的流派?我可以读取这首歌,但我如何获取该歌曲的流派,它存储在哪里?

谢谢!

最佳答案

检查这段代码:

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, 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, null, 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 - 获取歌曲的流派,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3728921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com