Created
April 8, 2018 00:56
-
-
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
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.*; | |
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() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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