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 › Play sound more than once
Page Index Toggle Pages: 1
Play sound more than once (Read 1821 times)
Play sound more than once
Nov 30th, 2009, 12:02pm
 
Hi, im trying to write a program where when every time you press "b" the sound "found.wav" plays. I can get it to play once, but I don't know how to play it again. Any tips?
Here's the code:

import ddf.minim.*;

AudioPlayer player;
Minim minim;

void setup()
{
 size(1010, 730);
 
   minim = new Minim(this);
 
 // load a file, give the AudioPlayer buffers that are 1024 samples long
 // player = minim.loadFile("found.wav");
 
 // load a file, give the AudioPlayer buffers that are 2048 samples long
 player = minim.loadFile("found.wav", 2048);
 // play the file
 background(0);
}

void draw()


{
if (keyPressed){
  if (key == 'b' || key == 'B'){
 player.play();

  }
}
}

Re: Play sound more than once
Reply #1 - Nov 30th, 2009, 1:25pm
 
I've added rewind() into my code so it can replay the sound but now it just repeats it when the button is held in, which I don't want! I just want a single activation when a button is held on.

import ddf.minim.*;

AudioPlayer alert;
Minim minim;

void setup()
{
 size(512, 200);

 minim = new Minim(this);
 
 // load a file, give the AudioPlayer buffers that are 1024 samples long
 // player = minim.loadFile("found.wav");
 
 // load a file, give the AudioPlayer buffers that are 2048 samples long
alert = minim.loadFile("found.wav", 2048);
 // play the file

}

void draw()
{
 background(0);
 // the values returned by left.get() and right.get() will be between -1 and 1,
 // so we need to scale them up to see the waveform
 // note that if the file is MONO, left.get() and right.get() will return the same value
if (keyPressed){
  if (key == 'b' || key == 'B'){
 alert.play();
 alert.rewind();

}
}
}

help!
Page Index Toggle Pages: 1