Created
December 8, 2015 17:57
-
-
Save tmshv/0f470a8d14eeab8fba62 to your computer and use it in GitHub Desktop.
Processing Sound Toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.sound.*; | |
class Sound { | |
SoundFile file; | |
boolean playing; | |
Sound(PApplet app, String path){ | |
file = new SoundFile(app, path); | |
playing = true; | |
} | |
void loop(){ | |
if(file != null) file.loop(); | |
} | |
void play(){ | |
if(file != null){ | |
playing = true; | |
file.play(); | |
} | |
} | |
void stop(){ | |
if(file != null){ | |
playing = false; | |
file.stop(); | |
} | |
} | |
void toggle(){ | |
if(playing) stop(); | |
else play(); | |
} | |
} | |
Sound sound1; | |
Sound sound2; | |
void setup() { | |
sound1 = new Sound(this, "sound1.mp3"); | |
sound2 = new Sound(this, "sound2.mp3"); | |
sound1.loop(); | |
sound2.loop(); | |
sound2.stop(); | |
} | |
void mousePressed(){ | |
sound1.toggle(); | |
sound2.toggle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment