Example usage for javax.sound.sampled Clip getFormat

List of usage examples for javax.sound.sampled Clip getFormat

Introduction

In this page you can find the example usage for javax.sound.sampled Clip getFormat.

Prototype

AudioFormat getFormat();

Source Link

Document

Obtains the current format (encoding, sample rate, number of channels, etc.) of the data line's audio data.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    DataLine.Info info = null;//from   ww  w. j a  v a 2s  . c o m
    Clip clip = (Clip) AudioSystem.getLine(info);
    double durationInSecs = clip.getBufferSize()
            / (clip.getFormat().getFrameSize() * clip.getFormat().getFrameRate());

}

From source file:SimpleSoundPlayer.java

public double getDuration() {
    double duration = 0.0;
    if (currentSound instanceof Sequence) {
        duration = ((Sequence) currentSound).getMicrosecondLength() / 1000000.0;
    } else if (currentSound instanceof BufferedInputStream) {
        duration = sequencer.getMicrosecondLength() / 1000000.0;
    } else if (currentSound instanceof Clip) {
        Clip clip = (Clip) currentSound;
        duration = clip.getBufferSize() / (clip.getFormat().getFrameSize() * clip.getFormat().getFrameRate());
    }//from   w  w w  .  ja va2  s  . c  om
    return duration;
}