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 › Sample isn't stopping
Page Index Toggle Pages: 1
Sample isn't stopping (Read 1115 times)
Sample isn't stopping
Jun 20th, 2006, 3:42pm
 
Hi,
I'm trying to stop() a sample that's playing in an internal class and i get a null pointer exception. I noticed that the method isPlaying() isn't working either. Method play() is working.

Here is a piece of the code that i'm using these methods:

void press() {
   if(bover && mousePressed) {
     press = true;
     locked = true;
     sound = new Sample(swave);

     if (sound.isPlaying()){
       sound.stop(1);
       sound = null;
       println("stamathse");
     }
     else{
       sound.play();
       println("isPlaying");
     }
         }
   else {
     press = false;
   }
 }

 void release(){
   locked = false;
 }
 void drag(){
   sound.stop(1);
 }
Re: Sample isn't stopping
Reply #1 - Jun 20th, 2006, 10:49pm
 
are you using sonia or ess, or is this just a java problem?
Re: Sample isn't stopping
Reply #2 - Jun 20th, 2006, 11:15pm
 
i' ve tried both ess and sonia and it trhows me the same exception. So i guess it's a java problem.
Here is all the inner class:

class SoundBox{
 int posx;
 int posy;
 int nx;
 int ny;
 int rsize;
 int bdifx = 0;
 int bdify = 0;

 boolean otherslocked = false;
 boolean locked = false;
 boolean press;
 SoundBox[] others;
 String sbox;
 Sample sound;
 String swave;
 String fotext;

 SoundBox(int rpx, int rpy, int rs, int difx, int dify, SoundBox[] o, String string, String wavestring){
   nx = rpx;
   ny = rpy;

   bdifx = difx;
   bdify = dify;

   rsize = rs;

   others = o;

   sbox = string;

   swave = wavestring;
 }

 void update()
 {
   posx =nx + bdifx;

   posy =ny + bdify;

   for(int i=0; i<num; i++) {
     if(others[i].locked == true) {
       otherslocked = true;
       break;
     }
     else {
       otherslocked = false;
     }  
   }



   if(press) {

     bdifx = lock(mouseX-rsize/2,0,w-rsize/2);
     bdify = lock(mouseY-rsize/2,0,h-rsize/2);
   }

   if (posy != ny || posx != nx){

     posy = bdify;
     posx = bdifx;
   }

   if(otherslocked == false) {
     over();
     press();
   }


 }

 void over() {
   if(overs (posx, posy, rsize)) {
     bover = true;
   }
   else {
     bover = false;
   }
 }

 void press() {
   if(bover && mousePressed) {
     press = true;
     locked = true;
     sound = new Sample(swave);

     if (sound.isPlaying()){
       sound.stop(1);
       sound = null;
       println("stamathse");
     }
     else{
       sound.play();
       println("isPlaying");
     }
         }
   else {
     press = false;
   }
 }

 void release(){
   locked = false;
 }
 void drag(){
   sound.stop(1);
 }


 void display(){


   if(bover){
     fill(231, 199, 58, 155);

   }
   else{
     fill(245, 228, 47, 155);
   }

   if(press) {
     fill(255, 255, 255, 30);
     stroke(255);
   }
   else{
     stroke(88);
   }
   rect(posx, posy, rsize, rsize);    

   textFont(bfont,10);    
   fill(0);                
   text(sbox, posx, posy, rsize, rsize);  

 }

 int positionx(){
   return posx;
 }

 int positiony(){
   return posy;
 }

 String wavename(){
   return swave;
 }

 void writext(){

   int tx = positionx();
   int ty = positiony();
   //String swn = sBox[i].wavename();

   if(tx >= 0 && tx < w/3 && ty >= 6*(h/10) && ty <= h){
     fotext = swave +"  "+"Lyriki";
     println("---------------------");
   }
   else

       if(tx >= w/3 && tx < 2*(w/3) && ty >= 6*(h/10) && ty <= h){
       fotext = swave +"  "+"Dramatikh";
       println("*********************");

     }
     else

         if(tx >= 2*(w/3) && tx <3* (w/3) && ty >= 6*(h/10) && ty <= h){
         fotext = swave +"  "+"Elafria";
         println("SSSSSSSSSSSSSSSSSSSSSS");
       }
       else {
         fotext = "Den exei kathgoriopoih8ei";
       }

 }

 String pl (){
   return fotext;


 }

}
Re: Sample isn't stopping
Reply #3 - Jun 21st, 2006, 12:00pm
 
Well the syntax is slightly different. Ess doesn't have an isPlaying method or field for starters...
Re: Sample isn't stopping
Reply #4 - Jun 21st, 2006, 2:45pm
 
Yes I know, this code is with the sonia import. When i used ess i didn't use the isPlaying() method...
Page Index Toggle Pages: 1