相信很多人都遇到amr格式的音频文件不能直接在网页播放的问题,有人使用QuickTime插件的辅助,以下介绍如何使用jave.jar包将amr格式的音频文件转成mp3格式,官方下载地址http://www.sauronsoftware.it/projects/jave/download.php,闲话少说,直接上例子
package com.nnbrightstar.lbtm.common.utils;
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.InputFormatException;
import java.io.File;
public class ChangeAudioFormat {
public static void main(String[] args) throws Exception {
String path1 = "E:\\Eclipse_Web\\lbtm\\webapp\\uploadFiles\\1395047224460.amr";
String path2 = "E:\\Eclipse_Web\\lbtm\\webapp\\uploadFiles\\1395047224460.mp3";
changeToMp3(path1, path2);
}
public static void changeToMp3(String sourcePath, String targetPath) {
File source = new File(sourcePath);
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
Encoder encoder = new Encoder();
audio.setCodec("libmp3lame");
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
try {
encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InputFormatException e) {
e.printStackTrace();
} catch (EncoderException e) {
e.printStackTrace();
}
}
}