I've been trying to figure this out for ages. The Stop()
function doesn't to work in the if statement (the songs just play on top of each other rather than pausing and rewinding). If I place the Stop()
function call outside the if statement, it seems like it works (ie no file is played at all which is expected behavior) Wondering if anyone could shed some light?
--------------SAMPLE OF CODE -------------------------
import processing.serial.*;
import ddf.minim.*;
String id;
Card Card1 = new Card();
Minim minim;//audio context;
AudioPlayer Backgroundplayer;
public class Card{ // CARD OBJECT so can set up each card.
String id;
String FileToPlay;
boolean Playing = false;
AudioPlayer player;
public Card(){}
public Card(String ID, String FILETOPLAY){
id = ID;
FileToPlay = FILETOPLAY;
}
void Load(){
player = minim.loadFile(FileToPlay);
}
void Play(){
if(Playing == false){
player.play();
Playing = true;
println("PLaying");
}else if(Playing == true){
Playing = false;
Stop();
}
}
void Stop(){
println("Stopping");
player.pause();
player.rewind();
}
}
void setup() {
size(400, 300);
}
void draw() {
}
void mouseClicked() {
Card1.id = id;
Card1.FileToPlay = "drumploop.wav";
Card1.Load();
Card1.Play();
}
The desired outcome is to play different sounds with each card. However, when a card is scanned, and if the card is already playing a clip, when its scanned again it should stop that assigned clip from playing, whilst the remaining other clips still play.