Search in sources :

Example 1 with IBXM

use of ibxm.IBXM in project MinecraftForge by MinecraftForge.

the class CodecIBXM method initialize.

/**
 * Prepares an audio stream to read from.  If another stream is already opened,
 * it will be closed and a new audio stream opened in its place.
 * @param url URL to an audio file to stream from.
 * @return False if an error occurred or if end of stream was reached.
 */
@Override
public boolean initialize(URL url) {
    initialized(SET, false);
    cleanup();
    if (url == null) {
        errorMessage("url null in method 'initialize'");
        cleanup();
        return false;
    }
    InputStream is = null;
    try {
        is = url.openStream();
    } catch (IOException ioe) {
        errorMessage("Unable to open stream in method 'initialize'");
        printStackTrace(ioe);
        return false;
    }
    if (ibxm == null)
        ibxm = new IBXM(48000);
    if (myAudioFormat == null)
        myAudioFormat = new AudioFormat(48000, 16, 2, true, true);
    try {
        setModule(loadModule(is));
    } catch (IllegalArgumentException iae) {
        errorMessage("Illegal argument in method 'initialize'");
        printStackTrace(iae);
        if (is != null) {
            try {
                is.close();
            } catch (IOException ioe) {
            }
        }
        return false;
    } catch (IOException ioe) {
        errorMessage("Error loading module in method 'initialize'");
        printStackTrace(ioe);
        if (is != null) {
            try {
                is.close();
            } catch (IOException ioe2) {
            }
        }
        return false;
    }
    if (is != null) {
        try {
            is.close();
        } catch (IOException ioe) {
        }
    }
    endOfStream(SET, false);
    initialized(SET, true);
    return true;
}
Also used : DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IBXM(ibxm.IBXM) AudioFormat(javax.sound.sampled.AudioFormat)

Aggregations

IBXM (ibxm.IBXM)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 AudioFormat (javax.sound.sampled.AudioFormat)1