3-5. Synchronizing Animation and Media
Problem
You want to incorporate animated effects in your media display. For example, you want to scroll “The End” after a video is finished playing.
Solution
Use recipe 3-3 together with recipe 2-2. Receipe 3-3 shows how to respond to media events. Recipe 2-2 demonstrates how to use javafx.animation.TranslateTransition
to animate text.
The following code demonstrates an attached action when an end of a media event is triggered:
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
closedCaption.setText("");
animateTheEnd.getNode().setOpacity(.90);
animateTheEnd.playFromStart();
}
});
Shown here is a method that creates a translateTransition
of a Text
node ...
Get JavaFX 2.0: Introduction by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.