mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
fix for bug #208, sound not playing the second time around
This commit is contained in:
+25
-1
@@ -41,8 +41,9 @@ import javax.sound.sampled.*;
|
||||
* Java Alamanac</A>
|
||||
*/
|
||||
public class PSound2 extends PSound {
|
||||
Clip clip;
|
||||
public Clip clip;
|
||||
FloatControl gainControl;
|
||||
boolean stopCalled;
|
||||
|
||||
|
||||
public PSound2(PApplet iparent, InputStream input) {
|
||||
@@ -111,6 +112,22 @@ public class PSound2 extends PSound {
|
||||
clip.addLineListener(new LineListener() {
|
||||
public void update(LineEvent event) {
|
||||
if (event.getType() == LineEvent.Type.STOP) {
|
||||
if (!stopCalled) {
|
||||
// if the stop() method was called, then the clip
|
||||
// is already being stopped, and stopping it here will
|
||||
// may pre-empt it from being immediately restarted.
|
||||
// i.e. with the code sound.stop(); sound.play();
|
||||
if (playing()) {
|
||||
// when playing, needs to shut everything off
|
||||
clip.stop();
|
||||
clip.setFramePosition(0);
|
||||
} else {
|
||||
// if not playing, just needs to reset things
|
||||
clip.stop();
|
||||
}
|
||||
}
|
||||
stopCalled = false;
|
||||
|
||||
try {
|
||||
soundEventMethod.invoke(parent,
|
||||
new Object[] { PSound2.this });
|
||||
@@ -138,6 +155,11 @@ public class PSound2 extends PSound {
|
||||
}
|
||||
|
||||
|
||||
public boolean playing() {
|
||||
return clip.isActive();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* either sets repeat flag, or begins playing (and sets)
|
||||
*/
|
||||
@@ -170,11 +192,13 @@ public class PSound2 extends PSound {
|
||||
* Stops the audio and rewinds to the beginning.
|
||||
*/
|
||||
public void stop() {
|
||||
//System.out.println("method stop");
|
||||
// clip may become null in the midst of this method
|
||||
//if (clip != null) clip.stop();
|
||||
//if (clip != null) clip.setFramePosition(0);
|
||||
clip.stop();
|
||||
clip.setFramePosition(0);
|
||||
stopCalled = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user