We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › [Minim] stop() method
Page Index Toggle Pages: 1
[Minim] stop() method (Read 595 times)
[Minim] stop() method
Jan 25th, 2008, 11:38pm
 
I'm now starting with manuals of Minim blog. At the very beginning of it, it is emphasized that 'before your program exits, it must close any audio I/O classes', and 'A good way to ensure this happens is to define a stop method in your sketch where you close all audio classes'. The below is a sample code to play back a file, in which I added a few print() commands to see the order of execution. The reason why I wanted to see the order is that in 'draw()' method, there is no line calling 'stop()' method. As I know, a method should be called in 'draw()' to be executed. What is I'm missing?

and also, I moved 'song.play()' inside 'draw()'..but the result is the same - just played once. Why isn't the file played over and over? It's different from when I draw something.

I'm afraid that I'm asking very dumb questions =(

--------------------

import ddf.minim.*;

AudioPlayer song;

void setup()
{
 size(100, 100);

 // always start Minim first!
 Minim.start(this);

 // this loads mysong.wav from the data folder
 song = Minim.loadFile("pianoLoop.wav");
 song.play();
 delay(200);
 println("after play");
}

void draw()
{
 println("before background");
 background(0);
 println("after background");
}

void stop()
{
 println("the first line of stop()");
 song.close();
 super.stop();
 println("the last line of stop()");
}
Re: [Minim] stop() method
Reply #1 - Jan 26th, 2008, 7:16am
 
When you define a stop() method in your sketch you are overriding the stop() method defined by PApplet, which is the Java class that you sketch extends. That means that when the user presses esc or clicks on the X to close the program, the stop() method that you have defined will be called instead of the one in PApplet. This allows you to do any cleanup required  that is specific to your app, such as closing audio resources, and then you can call super.stop(), which lets PApplet do the cleanup it needs to do.

The reason that the file only plays once is that when you tell an AudioPlayer to play, it just plays once. That's just how it works. If you want it to play again, you need to rewind() it and call play() again.
Page Index Toggle Pages: 1