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
you can use this code:
(change to AudioSnippet which gives you more info about its status)

  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. Minim minim; 
  8. AudioSnippet alert; 

  9. boolean hault;
  10. boolean donePlaying=false;
  11. float elapsedTime=0;

  12. void setup() {
  13.   size(310, 220);
  14.   fill(50); 
  15.   textSize(30); 
  16.   text("PABLO", 105, 50); 
  17.   textSize(20); 
  18.   text("Press 'H' to hault Program", 25, 100); 
  19.   
  20.   // Sound Output Setup 
  21.   minim = new Minim(this);
  22.   alert = minim.loadSnippet("siren.mp3"); 
  23. }

  24. void draw() {

  25.       if(hault&&!alert.isPlaying())
  26.       {
  27.       hault = false; //although you don't need to change the value of halt 
  28.                       //(unless you want to write its state to a file before exitting)
  29.       //noLoop();    //and you don't need this, exit() stops the loop
  30.       exit(); 
  31.       }  
  32. }

  33. void keyPressed() {
  34.   if (key == 'h') {
  35.     hault = true; 
  36.     alert.play(); 
  37.   }
  38. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles