Skip to content

Instantly share code, notes, and snippets.

@vizhen
Created January 17, 2014 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vizhen/8470359 to your computer and use it in GitHub Desktop.
Save vizhen/8470359 to your computer and use it in GitHub Desktop.
Android自带解析音乐文件标签功能
/**解析音乐标签
* 测试发现无法解析wma音乐文件
* 可解析mp3 ma4等
* Created by junny on 12/17/13.
*/
public class MusicParseUtil {
public static String getAlbum(String filePath){
String album;
try {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(filePath);
album = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
} catch (Exception e) {
album = null;
}
return album;
}
public static String getTitle(String filePath){
String title;
try {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(filePath);
title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
} catch (Exception e) {
title = null;
}
return title;
}
public static String getArtist(String filePath){
String artist;
try{
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(filePath);
artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
}catch (Exception e){
artist = null;
}
return artist;
}
public static byte[] getMusicThumbail(String filPath){
byte[] pic;
try{
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(filPath);
pic = mediaMetadataRetriever.getEmbeddedPicture();
}catch (Exception e){
pic = null;
}
return pic;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment