Mp3文件可以使用这个
mp3 SPI support来处理,但是我没有找到类似于mp4文件的东西.
任何帮助将不胜感激.
–update
我想做的是获取文件的大小,就像使用这个代码的wave文件一样:
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
AudioFormat format = audioInputStream.getFormat();
long audioFileLength = file.length();
int frameSize = format.getFrameSize();
float frameRate = format.getFrameRate();
float durationInSeconds = (audioFileLength / (frameSize * frameRate));
– 回答
以下是使用@mdma(IBM工具包)提示的答案代码:
/**
* Use IBMPlayerForMpeg4SDK to get mp4 file duration.
*
* @return the mp4File duration in milliseconds.
*/
public static long getMp4Duration(File mp4File) throws IllegalStateException,IOException {
PlayerControl playerControl = PlayerFactory.createLightweightMPEG4Player();
playerControl.open(mp4File.getAbsolutePath());
long mili = playerControl.getDuration();
// int sec = (int) ((mili / 1000) % 60);
// int min = (int) ((mili / 1000) / 60);
// System.out.println("IBM Tookit result = " + min + ":" + sec);
return mili;
}
–