sorry, made one mistake, here is the patch again, remember that streamingHint case is not handled correctly:
Code:
Index: src/org/newdawn/slick/Music.java
===================================================================
--- src/org/newdawn/slick/Music.java (revision 1529)
+++ src/org/newdawn/slick/Music.java (working copy)
@@ -1,5 +1,6 @@
package org.newdawn.slick;
+import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
@@ -7,6 +8,7 @@
import org.newdawn.slick.openal.AudioImpl;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.Log;
+import org.newdawn.slick.util.ResourceLoader;
/**
* A piece of music loaded and playable within the game. Only one piece of music can
@@ -77,44 +79,21 @@
/**
* Create and load a piece of music (either OGG or MOD/XM)
*
- * @param ref The location of the music
+ * @param url The location of the music
* @throws SlickException
*/
- public Music(URL ref) throws SlickException {
- this(ref, false);
+ public Music(URL url) throws SlickException {
+ this(url.getFile(), false);
}
/**
* Create and load a piece of music (either OGG or MOD/XM)
*
* @param url The location of the music
- * @param streamingHint A hint to indicate whether streaming should be used if possible
* @throws SlickException
*/
public Music(URL url, boolean streamingHint) throws SlickException {
- SoundStore.get().init();
- String ref = url.getFile();
-
- try {
- if (ref.toLowerCase().endsWith(".ogg")) {
- if (streamingHint) {
- sound = SoundStore.get().getOggStream(url);
- } else {
- sound = SoundStore.get().getOgg(url.openStream());
- }
- } else if (ref.toLowerCase().endsWith(".wav")) {
- sound = SoundStore.get().getWAV(url.openStream());
- } else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
- sound = SoundStore.get().getMOD(url.openStream());
- } else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
- sound = SoundStore.get().getAIF(url.openStream());
- } else {
- throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
- }
- } catch (Exception e) {
- Log.error(e);
- throw new SlickException("Failed to load sound: "+url);
- }
+ this(url.getFile(), streamingHint);
}
/**
@@ -125,27 +104,40 @@
* @throws SlickException
*/
public Music(String ref, boolean streamingHint) throws SlickException {
- SoundStore.get().init();
+ this(ResourceLoader.getResourceAsStream(ref), ref, streamingHint);
+ }
+
+ /**
+ * Create and load a piece of music (either OGG or MOD/XM)
+ * @param inputStream the stream of the music.
+ * @param ref The location of the music
+ * @param streamingHint A hint to indicate whether streaming should be used if possible
+ * @throws SlickException
+ */
+ public Music(InputStream inputStream, String ref, boolean streamingHint) throws SlickException {
+ SoundStore soundStore = SoundStore.get();
+ soundStore.init();
try {
if (ref.toLowerCase().endsWith(".ogg")) {
if (streamingHint) {
- sound = SoundStore.get().getOggStream(ref);
+ // don't know how to deal with this case.
+ sound = soundStore.getOggStream(ref);
} else {
- sound = SoundStore.get().getOgg(ref);
+ sound = soundStore.getOgg(ref, inputStream);
}
} else if (ref.toLowerCase().endsWith(".wav")) {
- sound = SoundStore.get().getWAV(ref);
+ sound = soundStore.getWAV(ref, inputStream);
} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
- sound = SoundStore.get().getMOD(ref);
+ sound = soundStore.getMOD(ref, inputStream);
} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
- sound = SoundStore.get().getAIF(ref);
+ sound = soundStore.getAIF(ref, inputStream);
} else {
throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
}
} catch (Exception e) {
Log.error(e);
- throw new SlickException("Failed to load sound: "+ref);
+ throw new SlickException("Failed to load music: "+ref);
}
}
UPDATE: fixed patch format.