Merge pull request #23 from fluddokt/omaster
Fixes Music Ended (hopefully)
This commit is contained in:
commit
64f5d5032d
|
@ -252,6 +252,7 @@ public class MusicController {
|
||||||
*/
|
*/
|
||||||
public static void play(boolean loop) {
|
public static void play(boolean loop) {
|
||||||
if (trackExists()) {
|
if (trackExists()) {
|
||||||
|
trackEnded = false;
|
||||||
if (loop)
|
if (loop)
|
||||||
player.loop();
|
player.loop();
|
||||||
else
|
else
|
||||||
|
|
|
@ -49,6 +49,9 @@ public class Music {
|
||||||
/** The music currently being played or null if none */
|
/** The music currently being played or null if none */
|
||||||
private static Music currentMusic;
|
private static Music currentMusic;
|
||||||
|
|
||||||
|
/** The lock object for synchronized modification to Music*/
|
||||||
|
private static Object musicLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Poll the state of the current music. This causes streaming music
|
* Poll the state of the current music. This causes streaming music
|
||||||
* to stream and checks listeners. Note that if you're using a game container
|
* to stream and checks listeners. Note that if you're using a game container
|
||||||
|
@ -57,10 +60,11 @@ public class Music {
|
||||||
* @param delta The amount of time since last poll
|
* @param delta The amount of time since last poll
|
||||||
*/
|
*/
|
||||||
public static void poll(int delta) {
|
public static void poll(int delta) {
|
||||||
|
synchronized (musicLock) {
|
||||||
if (currentMusic != null) {
|
if (currentMusic != null) {
|
||||||
SoundStore.get().poll(delta);
|
SoundStore.get().poll(delta);
|
||||||
if (!SoundStore.get().isMusicPlaying()) {
|
if (!SoundStore.get().isMusicPlaying()) {
|
||||||
if (!currentMusic.positioning && !currentMusic.playing) {
|
if (!currentMusic.positioning) {
|
||||||
Music oldMusic = currentMusic;
|
Music oldMusic = currentMusic;
|
||||||
currentMusic = null;
|
currentMusic = null;
|
||||||
oldMusic.fireMusicEnded();
|
oldMusic.fireMusicEnded();
|
||||||
|
@ -70,6 +74,7 @@ public class Music {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The sound from FECK representing this music */
|
/** The sound from FECK representing this music */
|
||||||
private Audio sound;
|
private Audio sound;
|
||||||
|
@ -155,7 +160,9 @@ public class Music {
|
||||||
try {
|
try {
|
||||||
if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
|
if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
|
||||||
if (streamingHint) {
|
if (streamingHint) {
|
||||||
|
synchronized (musicLock) {
|
||||||
sound = SoundStore.get().getOggStream(url);
|
sound = SoundStore.get().getOggStream(url);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sound = SoundStore.get().getOgg(url.openStream());
|
sound = SoundStore.get().getOgg(url.openStream());
|
||||||
}
|
}
|
||||||
|
@ -187,7 +194,12 @@ public class Music {
|
||||||
try {
|
try {
|
||||||
if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
|
if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
|
||||||
if (streamingHint) {
|
if (streamingHint) {
|
||||||
|
synchronized (musicLock) {
|
||||||
|
//getting a stream ends the current stream....
|
||||||
|
//which may cause a MusicEnded instead of of MusicSwap
|
||||||
|
//Not that it really matters for MusicController use
|
||||||
sound = SoundStore.get().getOggStream(ref);
|
sound = SoundStore.get().getOggStream(ref);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sound = SoundStore.get().getOgg(ref);
|
sound = SoundStore.get().getOgg(ref);
|
||||||
}
|
}
|
||||||
|
@ -286,6 +298,7 @@ public class Music {
|
||||||
* @param loop if false the music is played once, the music is looped otherwise
|
* @param loop if false the music is played once, the music is looped otherwise
|
||||||
*/
|
*/
|
||||||
private void startMusic(float pitch, float volume, boolean loop) {
|
private void startMusic(float pitch, float volume, boolean loop) {
|
||||||
|
synchronized (musicLock) {
|
||||||
if (currentMusic != null) {
|
if (currentMusic != null) {
|
||||||
currentMusic.stop();
|
currentMusic.stop();
|
||||||
currentMusic.fireMusicSwapped(this);
|
currentMusic.fireMusicSwapped(this);
|
||||||
|
@ -304,6 +317,7 @@ public class Music {
|
||||||
setPosition(requiredPosition);
|
setPosition(requiredPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause the music playback
|
* Pause the music playback
|
||||||
|
@ -317,8 +331,11 @@ public class Music {
|
||||||
* Stop the music playing
|
* Stop the music playing
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
synchronized (musicLock) {
|
||||||
|
playing = false;
|
||||||
sound.stop();
|
sound.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resume the music playback
|
* Resume the music playback
|
||||||
|
@ -414,6 +431,7 @@ public class Music {
|
||||||
* @return True if the seek was successful
|
* @return True if the seek was successful
|
||||||
*/
|
*/
|
||||||
public boolean setPosition(float position) {
|
public boolean setPosition(float position) {
|
||||||
|
synchronized (musicLock) {
|
||||||
if (playing) {
|
if (playing) {
|
||||||
requiredPosition = -1;
|
requiredPosition = -1;
|
||||||
|
|
||||||
|
@ -429,6 +447,7 @@ public class Music {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The position into the sound thats being played
|
* The position into the sound thats being played
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class OpenALStreamPlayer {
|
||||||
private int remainingBufferCount;
|
private int remainingBufferCount;
|
||||||
/** True if we should loop the track */
|
/** True if we should loop the track */
|
||||||
private boolean loop;
|
private boolean loop;
|
||||||
/** True if we've completed play back */
|
/** True if we've completed streaming to buffer (but may not be done playing) */
|
||||||
private boolean done = true;
|
private boolean done = true;
|
||||||
/** The stream we're currently reading from */
|
/** The stream we're currently reading from */
|
||||||
private AudioInputStream audio;
|
private AudioInputStream audio;
|
||||||
|
@ -158,6 +158,7 @@ public class OpenALStreamPlayer {
|
||||||
sampleSize = 2; // AL10.AL_FORMAT_MONO16
|
sampleSize = 2; // AL10.AL_FORMAT_MONO16
|
||||||
// positionOffset = 0;
|
// positionOffset = 0;
|
||||||
streamPos = 0;
|
streamPos = 0;
|
||||||
|
playedPos = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +190,7 @@ public class OpenALStreamPlayer {
|
||||||
* @param loop True if the stream should loop
|
* @param loop True if the stream should loop
|
||||||
* @throws IOException Indicates a failure to read from the stream
|
* @throws IOException Indicates a failure to read from the stream
|
||||||
*/
|
*/
|
||||||
public void play(boolean loop) throws IOException {
|
public synchronized void play(boolean loop) throws IOException {
|
||||||
this.loop = loop;
|
this.loop = loop;
|
||||||
initStreams();
|
initStreams();
|
||||||
|
|
||||||
|
|
|
@ -918,7 +918,7 @@ public class SoundStore {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.stream != null) {
|
if (this.stream != null && this.stream != stream) {
|
||||||
this.stream.close();
|
this.stream.close();
|
||||||
}
|
}
|
||||||
currentMusic = sources.get(0);
|
currentMusic = sources.get(0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user