Java源码示例:org.jaudiotagger.audio.mp3.MP3File
示例1
public static int getMp3TrackLength(File mp3File) {
try {
MP3File f = (MP3File) AudioFileIO.read(mp3File);
MP3AudioHeader audioHeader = (MP3AudioHeader)f.getAudioHeader();
return audioHeader.getTrackLength();
} catch(Exception e) {
e.printStackTrace();
return 0;
}
}
示例2
/**
* 根据时间生成新的mp3文件(分别支持VBR 和 CBR)
*
* @param targetFileStr 要生成的目标mp3文件
* @param beginTime
* @param endTime
* @return
*/
public void generateNewMp3ByTime(String targetFileStr, long beginTime, long endTime) throws Exception {
MP3File mp3 = new MP3File(this.mSourceMp3File);
MP3AudioHeader header = (MP3AudioHeader) mp3.getAudioHeader();
if (header.isVariableBitRate()) {
generateMp3ByTimeAndVBR(header, targetFileStr, beginTime, endTime);
} else {
generateMp3ByTimeAndCBR(header, targetFileStr, beginTime, endTime);
}
}
示例3
/**
* 获取MP3封面图片
*
* @param mp3File
* @return
*/
public static byte[] getMP3Image(File mp3File) {
byte[] imageData = null;
try {
MP3File mp3file = new MP3File(mp3File);
AbstractID3v2Tag tag = mp3file.getID3v2Tag();
AbstractID3v2Frame frame = (AbstractID3v2Frame) tag.getFrame("APIC");
FrameBodyAPIC body = (FrameBodyAPIC) frame.getBody();
imageData = body.getImageData();
} catch (Exception e) {
e.printStackTrace();
}
return imageData;
}
示例4
private static String getMetaInfo(MP3File file, String key) {
if (file.getID3v2Tag() == null || file.getID3v2Tag().frameMap == null
|| file.getID3v2Tag().frameMap.get(key) == null)
return null;
return ((AbstractID3v2Frame) file.getID3v2Tag().frameMap.get(key)).getBody().toString();
}
示例5
public static boolean setMetaInfo(MP3File file, FieldKey key, String value) throws FieldDataInvalidException {
if (file.getID3v2Tag() == null)
return false;
file.getID3v2Tag().setField(key, value);
return true;
}