Changed some methods in OpenALStreamPlayer to synchornized methods.

Seems to work with ogg now too.

Hopefully this fixes it, but I don't 
actually know much about concurrency.

However it stills throws "Could not clear SoundStore sources, err"
and so it remains removed.
This commit is contained in:
fd 2015-02-09 21:33:37 -05:00
parent 6883e2ab44
commit 08406ac038
3 changed files with 25 additions and 15 deletions

View File

@ -79,15 +79,15 @@ public class MusicController {
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
case "ogg":
//trackLoader = new Thread() {
// @Override
// public void run() {
trackLoader = new Thread() {
@Override
public void run() {
//Loading ogg async seems to screw up
//So does mp3, but much less
loadTrack(osu.audioFilename, osu.previewTime, loop);
// }
//};
//trackLoader.start();
}
};
trackLoader.start();
break;
case "mp3":
trackLoader = new Thread() {
@ -95,7 +95,7 @@ public class MusicController {
public void run() {
loadTrack(osu.audioFilename, osu.previewTime, loop);
//convertMp3(osu.audioFilename);
// if (!Thread.currentThread().isInterrupted())
//if (!Thread.currentThread().isInterrupted())
// loadTrack(wavFile, osu.previewTime, loop);
}
};
@ -133,13 +133,14 @@ public class MusicController {
public static void playAt(final int position, final boolean loop) {
if (trackExists()) {
setVolume(Options.getMusicVolume() * Options.getMasterVolume());
player.setPosition(position / 1000f);
trackEnded = false;
pauseTime = 0f;
if (loop)
player.loop();
else
player.play();
player.setPosition(position / 1000f);
}
}
@ -339,8 +340,14 @@ public class MusicController {
// TODO: properly interrupt instead of using deprecated Thread.stop();
// interrupt the conversion/track loading
if (isTrackLoading())
try {
trackLoader.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// trackLoader.interrupt();
trackLoader.stop();
//trackLoader.stop();
trackLoader = null;
// delete temporary WAV file

View File

@ -278,14 +278,14 @@ public class Music {
currentMusic.fireMusicSwapped(this);
}
playing = true;
currentMusic = this;
if (volume < 0.0f)
volume = 0.0f;
if (volume > 1.0f)
volume = 1.0f;
sound.playAsMusic(pitch, volume, loop);
playing = true;
currentMusic = this;
setVolume(volume);
if (requiredPosition != -1) {
setPosition(requiredPosition);

View File

@ -150,7 +150,7 @@ public class OpenALStreamPlayer {
/**
* Clean up the buffers applied to the sound source
*/
private void removeBuffers() {
private synchronized void removeBuffers() {
IntBuffer buffer = BufferUtils.createIntBuffer(1);
//int queued = AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED);
@ -213,7 +213,7 @@ public class OpenALStreamPlayer {
*
* Most of the time this should be reasonably quick
*/
public void update() {
public synchronized void update() {
if (done) {
return;
}
@ -259,7 +259,7 @@ public class OpenALStreamPlayer {
* @param bufferId The ID of the buffer to fill
* @return True if another section was available
*/
public boolean stream(int bufferId) {
public synchronized boolean stream(int bufferId) {
//Thread.dumpStack();
try {
int count = audio.read(buffer);
@ -303,13 +303,14 @@ public class OpenALStreamPlayer {
* @param position Position in seconds.
* @return True if the setting of the position was successful
*/
public boolean setPosition(float position) {
public synchronized boolean setPosition(float position) {
try {
//int state = AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE);
//AL10.alSourceStop(source);
long samplePos = (long) (position*sampleRate)*sampleSize;
//System.out.println("offset:"+samplePos%sampleSize);
if(streamPos > samplePos){//(getPosition() > position) {
initStreams();
}
@ -334,6 +335,8 @@ public class OpenALStreamPlayer {
return false;
}
}
//System.out.println("offset2:"+samplePos%sampleSize);
/*while(streamPos%sampleSize!=0){
audio.read();
streamPos++;