/**
* This sketch demonstrates how to use the loop(int) method of a Playable class.
* The class used here is AudioPlayer, but you can also loop an AudioSnippet.
* When you call loop(int) it will make the Playable loop for the number of times
* you specify. So, loop(3) will loop the recording three times, which will result in the recording
* being played 4 times.
* If you want to make it stop looping you can call play() and it will finish the current loop
* and then stop. Press any of the number keys to make the player loop that many times. Text will be displayed
* on the screen indicating your most recent choice.
*
*/
import ddf.minim.*;
import ddf.minim.effects.*;
Minim minim;
AudioSnippet groove;
int loopcount;
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
groove = minim.loadSnippet("groove.mp3");
textFont(createFont("Arial", 12));
textMode(SCREEN);
}
void draw()
{
background(0);
text("The player has " + groove.loopCount() + " loops left.", 5, 15);
}
void keyPressed()
{
String keystr = String.valueOf(key);
int num = int(keystr);
if ( num > 0 && num < 10 )
{
groove.loop(num);
loopcount = num;
}
}
void stop()
{
// always close Minim audio classes when you are done with them
groove.close();
// always stop Minim before exiting.
minim.stop();
super.stop();
}