Created
January 17, 2014 09:01
-
-
Save vizhen/8470359 to your computer and use it in GitHub Desktop.
Android自带解析音乐文件标签功能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**解析音乐标签 | |
* 测试发现无法解析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