Sound Code in void draw makes me problem

You can open the following example in processing:

ProcSoundEx

It will give you an idea on how it works.

Then you can replace the example code with the following:

import processing.sound.*;

SoundFile soundfile;

void setup() {
  size(640, 360);
  background(255);

  //Load a soundfile
  soundfile = new SoundFile(this, "vibraphon.aiff");
}

void draw() {
}


void mousePressed() {
  if (soundfile.isPlaying() == 1) {
    soundfile.stop();
  } else {
    soundfile.play();
  }
}

What it will do is play and stop the sound alternatively every time you hit the mouse.