From 26b452f04fe4226e69f5276883ed5c754a4d50ee Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Thu, 22 May 2014 21:17:51 +0200 Subject: Fix various music playing bugs --- src/esieequest/view/app/UserInterface.java | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index ed8e78f..e0121a2 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -105,6 +105,7 @@ abstract class UserInterface implements Viewable, ActionListener { private final Timer timer; private TimerTask timerTask; + private boolean scenePlaying; private OggClip audio; private boolean muted; @@ -445,8 +446,10 @@ abstract class UserInterface implements Viewable, ActionListener { * Skips the currently player Scene. */ private void skipScene() { - this.timerTask.run(); - this.timerTask.cancel(); + if (this.scenePlaying) { + this.timerTask.run(); + this.timerTask.cancel(); + } } /** @@ -484,14 +487,14 @@ abstract class UserInterface implements Viewable, ActionListener { */ private void playAudio(final String fileName) { if (this.audio != null) { - this.audio.stop(); - this.audio.close(); + // stop() and close() are not working properly... + this.audio.pause(); } try { this.audio = new OggClip(UserInterface.SOUND_DIR + fileName + UserInterface.SOUND_EXT); - this.setAudioGain(); this.audio.play(); + this.setAudioGain(); } catch (final IOException e) { e.printStackTrace(); } @@ -508,7 +511,7 @@ abstract class UserInterface implements Viewable, ActionListener { /** * Sets the gain. * - * FIXME: PulseAudio does not comply with the JSAPI + * PulseAudio does not comply with the JSAPI => pause/play instead of muting */ private void setAudioGain() { if (this.audio == null) { @@ -519,9 +522,11 @@ abstract class UserInterface implements Viewable, ActionListener { } if (this.muted) { - this.audio.setGain(-1.0f); - } else { - this.audio.setGain(1.0f); + // this.audio.setGain(0.0f); + this.audio.pause(); + } else if (this.audio.isPaused()) { + // this.audio.setGain(-1.0f);$ + this.audio.resume(); } } @@ -611,10 +616,13 @@ abstract class UserInterface implements Viewable, ActionListener { this.setIllustration(scene.name()); this.playAudio(scene.name()); + this.scenePlaying = true; + this.timerTask = new TimerTask() { @Override public void run() { scene.getCallback().call(); + UserInterface.this.scenePlaying = false; } }; this.timer.schedule(this.timerTask, scene.getDuration()); @@ -623,8 +631,8 @@ abstract class UserInterface implements Viewable, ActionListener { @Override public void stopMusic() { if (this.audio != null) { - this.audio.stop(); - this.audio.close(); + // stop() and close() are not working properly... + this.audio.pause(); } } -- cgit v1.2.3