Search in sources :

Example 1 with AudioDevice

use of vazkii.symphony.lib.javazoom.jl.player.AudioDevice in project Symphony by Vazkii.

the class AdvancedPlayer method decodeFrame.

/**
 * Decodes a single frame.
 *
 * @return true if there are no more frames to decode, false otherwise.
 */
protected boolean decodeFrame() throws JavaLayerException {
    try {
        AudioDevice out = audio;
        if (out == null)
            return false;
        Header h = bitstream.readFrame();
        if (h == null)
            return false;
        // sample buffer set when decoder constructed
        SampleBuffer output = (SampleBuffer) decoder.decodeFrame(h, bitstream);
        synchronized (this) {
            out = audio;
            if (out != null) {
                out.write(output.getBuffer(), 0, output.getBufferLength());
            }
        }
        bitstream.closeFrame();
    } catch (RuntimeException ex) {
        throw new JavaLayerException("Exception decoding audio frame", ex);
    }
    return true;
}
Also used : AudioDevice(vazkii.symphony.lib.javazoom.jl.player.AudioDevice) SampleBuffer(vazkii.symphony.lib.javazoom.jl.decoder.SampleBuffer) Header(vazkii.symphony.lib.javazoom.jl.decoder.Header) JavaLayerException(vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)

Example 2 with AudioDevice

use of vazkii.symphony.lib.javazoom.jl.player.AudioDevice in project Symphony by Vazkii.

the class AdvancedPlayer method close.

/**
 * Cloases this player. Any audio currently playing is stopped
 * immediately.
 */
public synchronized void close() {
    AudioDevice out = audio;
    if (out != null) {
        closed = true;
        audio = null;
        // this may fail, so ensure object state is set up before
        // calling this method.
        out.close();
        lastPosition = out.getPosition();
        try {
            bitstream.close();
        } catch (BitstreamException ex) {
        }
    }
}
Also used : AudioDevice(vazkii.symphony.lib.javazoom.jl.player.AudioDevice) BitstreamException(vazkii.symphony.lib.javazoom.jl.decoder.BitstreamException)

Aggregations

AudioDevice (vazkii.symphony.lib.javazoom.jl.player.AudioDevice)2 BitstreamException (vazkii.symphony.lib.javazoom.jl.decoder.BitstreamException)1 Header (vazkii.symphony.lib.javazoom.jl.decoder.Header)1 JavaLayerException (vazkii.symphony.lib.javazoom.jl.decoder.JavaLayerException)1 SampleBuffer (vazkii.symphony.lib.javazoom.jl.decoder.SampleBuffer)1