Path: blob/master/SLICK_HOME/src/org/newdawn/slick/openal/AudioLoader.java
1461 views
package org.newdawn.slick.openal;12import java.io.IOException;3import java.io.InputStream;4import java.net.URL;56/**7* A utility to provide a simple and rational interface to the8* slick internals9*10* @author kevin11*/12public class AudioLoader {13/** AIF Format Indicator */14private static final String AIF = "AIF";15/** WAV Format Indicator */16private static final String WAV = "WAV";17/** OGG Format Indicator */18private static final String OGG = "OGG";19/** MOD/XM Format Indicator */20private static final String MOD = "MOD";21/** MOD/XM Format Indicator */22private static final String XM = "XM";2324/** True if the audio loader has be initialised */25private static boolean inited = false;2627/**28* Initialise the audio loader29*/30private static void init() {31if (!inited) {32SoundStore.get().init();33inited = true;34}35}3637/**38* Get audio data in a playable state by loading the complete audio into39* memory.40*41* @param format The format of the audio to be loaded (something like "XM" or "OGG")42* @param in The input stream from which to load the audio data43* @return An object representing the audio data44* @throws IOException Indicates a failure to access the audio data45*/46public static Audio getAudio(String format, InputStream in) throws IOException {47init();4849if (format.equals(AIF)) {50return SoundStore.get().getAIF(in);51}52if (format.equals(WAV)) {53return SoundStore.get().getWAV(in);54}55if (format.equals(OGG)) {56return SoundStore.get().getOgg(in);57}5859throw new IOException("Unsupported format for non-streaming Audio: "+format);60}6162/**63* Get audio data in a playable state by setting up a stream that can be piped into64* OpenAL - i.e. streaming audio65*66* @param format The format of the audio to be loaded (something like "XM" or "OGG")67* @param url The location of the data that should be streamed68* @return An object representing the audio data69* @throws IOException Indicates a failure to access the audio data70*/71public static Audio getStreamingAudio(String format, URL url) throws IOException {72init();7374if (format.equals(OGG)) {75return SoundStore.get().getOggStream(url);76}77if (format.equals(MOD)) {78return SoundStore.get().getMOD(url.openStream());79}80if (format.equals(XM)) {81return SoundStore.get().getMOD(url.openStream());82}8384throw new IOException("Unsupported format for streaming Audio: "+format);85}8687/**88* Allow the streaming system to update itself89*/90public static void update() {91init();9293SoundStore.get().poll(0);94}95}969798