Java Reference
In-Depth Information
Figure 16-4 . Paused event
// when paused event display pause message
mediaPlayer.setOnPaused(() -> {
pauseMessage.setText("Paused \nDuration: " +
mediaPlayer.currentTimeProperty().getValue().toMillis());
pauseMessage.setOpacity(.90);
});
How It Works
Event-driven architecture (EDA) is a prominent architectural pattern used to model
loosely coupled components and services that pass messages asynchronously. The
JavaFX team designed the Media API to be event-driven, and this recipe demonstrates
how to implement it in response to media events.
With event-based programming in mind, you will discover nonblocking or callback
behaviors when invoking functions. In this recipe, you will implement the display of
text in response to an onPaused event instead of placing your code into the pause
button. Instead of tying code directly to a button via an EventHandler , you will be
implementing code that will respond to the media player's onPaused event being
triggered. When responding to media events, you will be implementing
java.lang.Runnable s.
 
Search WWH ::




Custom Search