Java Reference
In-Depth Information
Let's take a look at the setOnEndOfMedia() method associated with the Me-
diaPlayer object. Just like in Recipe 16-3, you simply call the setOnEndOfMe-
dia() method by passing in a lambda expression implementing Runnable , which
contains the code that will invoke an animation. If you don't know how the animation
works, refer to Recipe 16-2. Once the event occurs, you will see the text scroll upward.
The following code snippet is from inside the scene.setOnDragDropped()
method:
mediaPlayer.setOnEndOfMedia(() -> {
closedCaption.setText("");
animateTheEnd.getNode().setOpacity(.90);
animateTheEnd.playFromStart();
});
For the sake of space, I trust you know where the code block would reside. If not,
refer to Recipe 16-3, in which you will notice other OnXXX properties methods. To see
the entire code listing and download the source code, visit the topic's website.
To animate "The End" you create a convenience createTheEnd() method to
create an instance of a Text node and return a TranslateTransition object to
the caller. The TranslateTransition that's returned does the following: it waits
a second before playing the video. Next is the interpolator in which you used the In-
terpolator.EASE_IN to move the Text node by easing in before a full stop. Last
is setting the Y property of the node to move from the bottom to the center of the view-
ing area.
The following code creates an animation that scrolls a node in an upward motion:
TranslateTransition scrollUp = new TranslateTransition();
scrollUp.setNode(theEnd);
scrollUp.setDuration(Duration.seconds(1));
scrollUp.setInterpolator(Interpolator.EASE_IN);
scrollUp.setFromY(scene.getHeight() + 40);
scrollUp.setToY(scene.getHeight()/2);
Summary
Search WWH ::




Custom Search