Example usage for javax.sound.sampled Clip getBufferSize

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

Introduction

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

Prototype

int getBufferSize();

Source Link

Document

Obtains the maximum number of bytes of data that will fit in the data line's internal buffer.

Usage

From source file:Main.java

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

    DataLine.Info info = null;//  w  w  w  . j  a va2  s .  co 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());
    }/* w  ww.  jav  a2s.  com*/
    return duration;
}