I currently have my EventHandler here:
theScene.setOnMouseClicked(
new EventHandler<MouseEvent>() {
public void handle(MouseEvent e) {
if (targetData.containsPoint(e.getX(), e.getY())) {
double x = 50 + 400 * Math.random();
double y = 50 + 400 * Math.random();
targetData.setCenter(x, y);
mediaPlayer.play(); //play hitsound
points.value++; //add points
} else {
points.value = 0; //miss
}
}
});
I also have my audio setup like so:
String hitNormal = ("hit.mp3");
Media sound = new Media(new File(hitNormal).toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound);
When I run my program, only the first click on the circle plays the hitsound, but all the following circles do not play the sound. I think what I have above should work since every time I click additional circles it always adds score. Since I have my mediaPlayer.play(); in the exact same if statement as the line that adds score, I expected the sound to play as well. How do I get my hitsound to play every time I click the circle?
EDIT: I added mediaPlayer.stop(); under points.value++ and it seems to occasionally play the hitsound but not always.
You properly need to check the status of media player, this method may helps mediaPlayer.getStatus()
.
when it's playing, another play()
method seem to do nothing because it change status to playing but it already does. see MediaPlayer and MediaPlayer.Status
try use below method in your code.
mediaPlayer.stop()
it will stop the media and reset current time to zero.
add this method when media is end. you can try as below code
mediaPlayer.setOnEndOfMedia(new Runnable()
{
public void run()
{
mediaPlayer.stop();
}
});
or use mediaPlayer.seek()
seek current time.
when previous media isn't yet to reach end, you need to pause it and seek current time to zero before next play()
.
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I need to run hourly analysis of elements that are stored in hbase, which means for each element, I need to get the previous hour's data to analyzeThe only problem is it's taking me more than 1 hour to scan everything when using a for loop without mapreduce
I am trying to run my app and keep encountering the error:
Im trying to write a code and i used the do while loop in an atempt to loop my main code after the user types in y or yes (case insensitive) into an InputDialog
Logging error messages is a requirement that is needed by the console as well as GUI applicationsTherefore the actual error logging functionality can be placed inside a common utility class so that client objects do not have to repeat these details