Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Want to play a sound at the end of my program... Having problem...

$
0
0
That's useful when you do a long task. Example:
  1. import ddf.minim.spi.*;
  2. import ddf.minim.signals.*;
  3. import ddf.minim.*;
  4. import ddf.minim.analysis.*;
  5. import ddf.minim.ugens.*;
  6. import ddf.minim.effects.*;
  7.  
  8. Minim minim;
  9. AudioSample alert;
  10. int duration;
  11.  
  12. final int SIZE = 16;
  13. boolean halt, stopping;
  14. int c;
  15.  
  16. void setup()
  17. {
  18.   size(240, 400);
  19.   noStroke();
  20.  
  21.   minim = new Minim(this);
  22.   alert = minim.loadSample("G:/Documents divers/Sounds/Huge Metal Door Slam.mp3");
  23.   duration = alert.length();
  24. }
  25.  
  26. void draw()
  27. {
  28.   if (halt)
  29.   {
  30.     alert.trigger();
  31.     halt = false;
  32.     stopping = true;
  33.     duration += millis();
  34.   }
  35.   if (stopping && millis() > duration)
  36.   {
  37.     exit();
  38.   }
  39.   if (!stopping)
  40.   {
  41.     fill(random(255), random(255), random(255));
  42.     rect(SIZE * (c % (width / SIZE)), SIZE * (c / (width / SIZE)), SIZE, SIZE);
  43.     halt = ++c > width * height / SIZE / SIZE;
  44.   }
  45. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles