我试图从网上检索mp3信息。但是,在播放mp3时,没有这样一个很好的示例/示例来检索诸如歌曲标题、艺术家等mp3信息。
我试图使用MediaStore.Audio.Media获取媒体信息,但它只检索内部/下载的媒体信息。我需要从服务器检索信息。
我列出了来自MP3列表的MP3列表文件。但我无法在安卓应用程序中列出mp3信息。
有人能告诉我从哪里可以得到可能的解决方案或一些有关这个问题的信息吗?
发布于 2015-08-05 08:35:11
我以AssetFileDescriptor为例编写代码。MediaMetadataRetriever setDataSource()方法可以用不同的参数(String、FileDescriptor、Uri)调用。您可以参考MediaMetadataRetriever的正式文档。
String albumName = null;
String title = null;
String artist = null;
try {
AssetFileDescriptor afd = getAssets().openFd("1.mp3");
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
albumName =
mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
title =
mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
artist =
mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.d("MediaMetadataRetriever","title " + title + " albumName " + albumName+ " artist " + artist );https://stackoverflow.com/questions/31824920
复制相似问题