We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi, im trying to do a gps android application on a xperia z. i'm playing a music file (wav) when i reach a location. the problem i encounter now is that when i reached the 1st area where the audio is been played, it play perfectly but when i reach the 2nd spot, the audio doesn't change, it just stuck with the 1st location audio. i'm using APMediaPlayer. i check online for a few days, i've tried "clear();" & "stop();" but it doesn't work. So i was wondering is there any textchanged event function for processing2?
(audio)my code:
void mousePressed(){
if (bus_01 < 50) // setting the distance to 50m
{
player = new APMediaPlayer(this); //create new APMediaPlayer
player.setMediaFile("north.wav"); //set the file (files are in data folder)
player.start();
player.setLooping(false); //restart playback end reached
player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0//start play back
}
else if (bus_02 < 50)// setting the distance to 50m
{
player = new APMediaPlayer(this); //create new APMediaPlayer
player.setMediaFile("south.wav"); //set the file (files are in data folder)
player.start();
player.setLooping(false); //restart playback end reached
player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0//start play back
}
}
Answers
It will be much easier to help you if you post an MCVE instead of a disconnected snippet.
But in order to debug your code, you need to answer a few questions: what are the values of bus_01 and bus_02 when you reach the second spot? Which if statement does the code enter?
Notice that you're using an if/else if statement, so if the code enters the first if statement, it will ignore the second one.
thank you so much for replying me i'm so sorry, i didn't know how i'm suppose to post on forum. But i think you catch what i'm trying to say. about the bus_01 and bus_02 is actually the distance from my location to the point i have set as my north and south.
"Notice that you're using an if/else if statement, so if the code enters the first if statement, it will ignore the second one." - i didn't know about this, what can i use to make it so that it will run through the everytime the gps refresh?
You should add some print statements to better understand what this code is doing. It will only ever enter ONE of those if statements. If the first if statement evaluates to true, it doesn't even look at the second one. Is that the behavior you want?
nope, i want it to go through both, meaning other it ring, it release the music which it is holding and run through both again. but i have no idea how to do it
I recommend reading the basic tutorials on if statements: http://www.processing.org/reference/else.html http://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html http://staticvoidgames.com/tutorials/basicConcepts/IfStatements.jsp
If that doesn't clear it up, I recommend creating an MCVE that tests how if/else statements work.
If you're still confused, post that MCVE here, and we'll go from there.