How make the minim library play sound only one time

    import ddf.minim.*;

    AudioPlayer song;
    AudioPlayer soong;
    AudioPlayer sooong;
    Minim minim;//audio context

    void setup() {
      size(600, 600);
      frameRate(20);

      minim = new Minim(this);
      song = minim.loadFile("Low.mp3", 5048);
      soong = minim.loadFile("Mid.mp3", 2048);
      sooong = minim.loadFile("High.mp3", 2048);
    }

    void draw() {
      if (mouseY > 400 && mouseY < 600) {
        song.play();
      }

      if (mouseY > 200 && mouseY < 400) {
        soong.play();
      }

      if (mouseY > 0 && mouseY < 200) {
        sooong.play();
      }
void stop() {
  super.stop();
}

How can I make Processing only play the sound one time when the mosueY reaches certain area? Thanks a lot!

Tagged:

Answers

  • Perhaps you gotta pause all the other 1s? :(|)

  • void draw() {
      s4.play();
      s4.rewind( );
    
      if (mouseY > 400 && mouseY < 600) {
        s1.play(1);
      }
    
      if (mouseY > 200 && mouseY < 400) {
        s2.play(1);
      }
    
      if (mouseY > 0 && mouseY < 200) {
        s3.play(1);
      }
    }
    

    I changed part of code like this, but Processing just still keeping playing weird sounds(not original ones).

  • edited November 2013

    perhaps use some sub-conditional for stopping others, like this:

     if (mouseY > 400 && mouseY < 600) {
        if(s2.isPlaying() || s3.isPlaying()){ // if s2 OR s3 is playing
            s2.pause();
            s2.rewind();
            s3.pause();
            s3.rewind();
        }
        s1.play(1);
      }
    

    and use 2 variations of this one for rest.

    btw, in minim documentation under rewind(), it states:

    Rewinds to the beginning. This does not stop playback.

    This should work in theory. Hopefully will work in your sketch.

    edit: sorry, I messed up numbers...

Sign In or Register to comment.