我想要获取音频文件的总时间(持续时间),单位为秒。音频文件可以是任何格式,例如 (.mp3, .wav, .wma 等)。
try {
File file = new File("C:/Users/Administrator/AppData/Local/Temp/" +
"01 - Ab Tere Bin Jee Lenge Hum-(MyMp3Singer.com).mp3");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
AudioFormat format = audioInputStream.getFormat();
long frames = audioInputStream.getFrameLength();
double durationInSeconds = (frames + 0.0) / format.getFrameRate();
System.out.println("duration in seconds"+durationInSeconds);
AudioFileFormat audioFileFormat = AudioSystem.getAudioFileFormat(file);
Map<String, Object> properties = audioFileFormat.properties();
System.out.println("properties"+properties.size()+"empy::"+properties.isEmpty());
for(String key: properties.keySet()){
System.out.println(key +" :: "+ properties.get(key).toString());
}
} catch (Exception e) {
System.out.println("Exception:::::" + e.getMessage());
}
我试过使用以上代码,但是它会出现以下错误:
Exception:::::could not get audio input stream from input file