How do I get a sound file's total time in Java?

前端 未结 2 468
离开以前
离开以前 2020-11-30 05:04

How do I get a sound file\'s total time in Java?

--UPDATE

Looks like this code does de work: long audioFileLength = audioFile.length();

    r         


        
2条回答
  •  猫巷女王i
    2020-11-30 05:27

    Given a File you can write

    File file = ...;
    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
    AudioFormat format = audioInputStream.getFormat();
    long frames = audioInputStream.getFrameLength();
    double durationInSeconds = (frames+0.0) / format.getFrameRate();  
    

提交回复
热议问题