I'm making a game in processing that has different background music in different scenes, and am using the minim library for AudioPlayer.
Currently, what I'm doing is importing/opening both audio files in my setup() function, calling player1.play() when the user triggers that scene, then when the user triggers the next scene, I call player1.close() and player2.play() to stop the first song and play the second one, and then player2.close() when that scene ends to stop the music.
Of course, if I want the user to be able to run this music again because he's playing the game through a second time, that's an issue because I've closed player1 and player2 and it causes a NullPointerException.
Is there a function/method for the audio player that allows me to temporarily stop/pause the background music from playing so that I can .play() it again later?
Hey, I'm trying to write a simple processing game that involves several PShapes. I keep getting a NullPointerException, but can't seem to identify where it is. The full error I'm getting is:
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
at processing.core.PApplet.runSketch(PApplet.java:9869)
at processing.core.PApplet.main(PApplet.java:9678)
Caused by: java.lang.NullPointerException
at processing.core.PApplet.loadShape(PApplet.java:10788)
at MakeYourOwnShake.<init>(MakeYourOwnShake.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at processing.core.PApplet.runSketch(PApplet.java:9867)
... 1 more
I went through and checked the file names against the .svg's in my data file, and they all seem to match, but I'm still getting the error. Here is my current code, it's mostly just a bunch of initializing variables and shapes at this point:
//draw backgroundGradient from (0,0), full width, full height
//shape(backgroundGradient,0,0,width,height);
//draw hostCat
//draw startScreenMessage
if(mousePressed){
startPage = false;
chooseChars = true;
}
}//end startPage
}//end draw()
The comment //slashes were just my way of checking the file names off as I went through my data file. Does anyone see what my issue might be, or is it definitely just a typo I missed with the PShape names?