Skip to content

Instantly share code, notes, and snippets.

@poanchen
Created April 8, 2018 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poanchen/20bc0cf8929f427a343280d30be1826b to your computer and use it in GitHub Desktop.
Save poanchen/20bc0cf8929f427a343280d30be1826b to your computer and use it in GitHub Desktop.
Demonstration of using multiple interfaces to play or stop music with the help of Processing Sound library
import processing.sound.*;
interface Class1 {
void playSong();
void stopSong();
}
interface Class2 {
void playSong();
void stopSong();
}
class Song1 implements Class1 {
SoundFile file;
String path = sketchPath("sample1.mp3");
Song1(PApplet applet) {
file = new SoundFile(applet, path);
}
void playSong() {
file.play();
}
void stopSong() {
file.stop();
}
}
class Song2 implements Class2 {
SoundFile file;
String path = sketchPath("sample2.mp3");
Song2(PApplet applet) {
file = new SoundFile(applet, path);
}
void playSong() {
file.play();
}
void stopSong() {
file.stop();
}
}
//runs once when the app first starts
void setup() {
// first play the first song
// wait for 10 secs
// then we stop the first song and start playing the second song
// wait for 5 secs
// then we stop the second song
Song1 s1 = new Song1(this);
s1.playSong();
delay(10000);
s1.stopSong();
Song2 s2 = new Song2(this);
s2.playSong();
delay(5000);
s2.stopSong();
}
//runs all the time, this is the main app loop
void draw() {
}
@poanchen
Copy link
Author

poanchen commented Apr 8, 2018

this code snippet was created to help one of the guy that comment on my site. Check out the comment here http://disq.us/p/1rjg5hq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment