v1.0.3: fixed audio issues on desktop caused by threading addition
This commit is contained in:
parent
e3ffc875ba
commit
30c00f95b6
|
@ -131,36 +131,43 @@ public enum Music {
|
|||
public void onCompletion(com.badlogic.gdx.audio.Music music) {
|
||||
//we do this in a separate thread to avoid graphics hitching while the music is prepared
|
||||
//FIXME this fixes graphics stutter but there's still some audio stutter, perhaps keep more than 1 player alive?
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (Music.INSTANCE) {
|
||||
if (trackList == null || trackList.length == 0 || player.isLooping() || music != player){
|
||||
return;
|
||||
}
|
||||
|
||||
Music.this.stop();
|
||||
|
||||
if (trackQueue.isEmpty()) {
|
||||
for (int i = 0; i < trackList.length; i++) {
|
||||
if (Random.Float() < trackChances[i]) {
|
||||
trackQueue.add(trackList[i]);
|
||||
}
|
||||
}
|
||||
if (shuffle) Collections.shuffle(trackQueue);
|
||||
}
|
||||
|
||||
if (!enabled || trackQueue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
play(trackQueue.remove(0), trackLooper);
|
||||
if (!DeviceCompat.isDesktop()) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
playNextTrack(music);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}.start();
|
||||
} else {
|
||||
//don't use a separate thread on desktop, causes errors and makes no performance difference(?)
|
||||
playNextTrack(music);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private synchronized void playNextTrack(com.badlogic.gdx.audio.Music music){
|
||||
if (trackList == null || trackList.length == 0 || music != player || player.isLooping()){
|
||||
return;
|
||||
}
|
||||
|
||||
Music.this.stop();
|
||||
|
||||
if (trackQueue.isEmpty()) {
|
||||
for (int i = 0; i < trackList.length; i++) {
|
||||
if (Random.Float() < trackChances[i]) {
|
||||
trackQueue.add(trackList[i]);
|
||||
}
|
||||
}
|
||||
if (shuffle) Collections.shuffle(trackQueue);
|
||||
}
|
||||
|
||||
if (!enabled || trackQueue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
play(trackQueue.remove(0), trackLooper);
|
||||
};
|
||||
|
||||
private synchronized void play(String track, com.badlogic.gdx.audio.Music.OnCompletionListener listener){
|
||||
try {
|
||||
player = Gdx.audio.newMusic(Gdx.files.internal(track));
|
||||
|
|
Loading…
Reference in New Issue
Block a user