org.jaudiotagger.audio.mp3.MP3File Java Examples

The following examples show how to use org.jaudiotagger.audio.mp3.MP3File. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AMRConvert.java    From youkefu with Apache License 2.0 6 votes vote down vote up
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;  
    }  
}
 
Example #2
Source File: Mp3CutLogic.java    From Mp3Cutter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据时间生成新的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);
    }
}
 
Example #3
Source File: Mp3InfoUtils.java    From Mp3Cutter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取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;
}
 
Example #4
Source File: Mp3InfoUtils.java    From Mp3Cutter with GNU General Public License v3.0 4 votes vote down vote up
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();
}
 
Example #5
Source File: Mp3InfoUtils.java    From Mp3Cutter with GNU General Public License v3.0 4 votes vote down vote up
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;
}