Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Use of If and Else conditional to make sound pause and play.

$
0
0

Hello! I am almost complete with my project. I have decided to use the keyboard function to have a certain key play a sound. I have gotten as far as that. But, I am stuck at how to pause the sound and also play for the same key. For Example: if you press a letter once, it'll play, and if you do it again, it'll pause it and so forth.

I've tried to use filename.rewind(); but that doesn't help from all my sounds playing at once.

void draw() {
  background(c);
  textSize(20);
  text("R for Spring S for Summer & W for Winter", 80, 100);
  flower.update();
  sun.update();
  fire.update();
  snowman.update();

  flower.draw();
  sun.draw();
  fire.draw();
  snowman.draw();

  if ((keyPressed == true) && ((key == 'S') || (key =='s'))) {
    summer.play();
    summer.rewind();
  }
  if ((keyPressed == true) &&((key == 'W') || (key=='w'))) {
    winter.play();
  }
  if ((keyPressed == true) && ((key == 'R') || (key =='r'))) {
    spring.play();
  }
  if ((keyPressed == true) && ((key == 'F') || (key =='f'))) {
    fall.play();
  }
}

thank you for your help

Melanie


Viewing all articles
Browse latest Browse all 2896

Trending Articles