Java Reference
In-Depth Information
That's it for media markers. That goes to show how you can coordinate special ef-
fects, animations, and so on during a video quite easily.
16-5. Synchronizing Animation and Me-
dia
Problem
You want to incorporate animated effects in your media display, such as scrolling the
text "The End" after the video is finished playing.
Solution
You simply use Recipe 16-3 together with Recipe 16-2. Recipe 16-3 shows how to re-
spond to media events and Recipe 16-2 demonstrates how to use the translate transition
to animate text.
The following code demonstrates an attached action when the end of a media event
is triggered:
mediaPlayer.setOnEndOfMedia(() -> {
closedCaption.setText("");
animateTheEnd.getNode().setOpacity(.90);
animateTheEnd.playFromStart();
});
The following method creates a translateTransition of a Text node con-
taining the string “The End” that appears after an end of media event is triggered:
public TranslateTransition createTheEnd(Scene scene) {
Text theEnd = new Text("The End");
theEnd.setFont(new Font(40));
theEnd.setStrokeWidth(3);
theEnd.setFill(Color.WHITE);
theEnd.setStroke(Color.WHITE);
theEnd.setX(75);
Search WWH ::




Custom Search