Java Reference
In-Depth Information
code shows the pauseButton and playButton controlling the mediaPlayer
object and setting the paused flag accordingly:
// pause media and swap button with play button
pauseButton.setOnMousePressed((MouseEvent me) -> {
if (mediaPlayer != null) {
buttonArea.getChildren().removeAll(pauseButton,
playButton);
buttonArea.getChildren().add(playButton);
mediaPlayer.pause();
paused = true;
}
});
// play media and swap button with pause button
playButton.setOnMousePressed((MouseEvent me) -> {
if (mediaPlayer != null) {
buttonArea.getChildren().removeAll(pauseButton,
playButton);
buttonArea.getChildren().add(pauseButton);
paused = false;
mediaPlayer.play();
}
});
That is how you create a video media player. In the next recipe, you learn how to
listen to media events and invoke actions.
16-3.
Controlling
Media
Actions
and
Events
Problem
You want the media player to provide feedback in response to certain events, such as
displaying the text “Paused” on the screen when the media player's paused event is
triggered.
Search WWH ::




Custom Search