Java Reference
In-Depth Information
MediaView and Effects
All of the normal effects that can be applied to a Node can also be applied to a MediaView . Some care must be taken
to ensure that the effects are not so expensive as to interfere with the smooth playback of the movie. With that caveat
in place, we go over some of the effects that are commonly in use with media player applications. Reflections (see
javafx.scene.effect.Reflection ) are a popular effect, specifically in demos that are meant to show off a platform's
graphical horsepower. A reflection can make the movie look as if it is sitting on a shiny surface. The effect is very
compelling because the reflection is updated in real time to match the movie. JavaFX's ColorAdjust effect can be
used to alter the colors in the movie for a fun and visually interesting effect. If you're in a more artsy kind of mood, the
SepiaTone effect might be just the thing. And, of course, there is the old reliable DropShadow effect to make the movie
look as if it is floating over the background. We encourage you to use the example programs and experiment with the
different effects in the javafx.scene.effect package. It is a fun and interesting way to learn about them.
Using Markers
The JavaFX 2.0 media API also includes support for media markers. These markers can be used to trigger events
during media playback. Every Media object contains an ObservableMap whose keys are String s and whose values are
Duration s. During playback, these markers trigger MediaMarkerEvent s at the Duration specified by the marker. These
events can be caught by passing an EventHandler to the MediaPlayer 's setOnMarker method. Listing 9-33 contains
the code for the VideoPlayer2 application that sets and then displays the text of these markers during video playback.
Although we show them here during video playback, the marker functionality is available during audio playback as well.
Listing 9-33. Displaying Media Markers in a Movie
public class VideoPlayer2 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
final Label markerText = new Label();
StackPane.setAlignment(markerText, Pos.TOP_CENTER);
String workingDir = System.getProperty("user.dir");
final File f = new File(workingDir, "../media/omgrobots.flv");
final Media m = new Media(f.toURI().toString());
final ObservableMap<String, Duration> markers = m.getMarkers();
markers.put("Robot Finds Wall", Duration.millis(3100));
markers.put("Then Finds the Green Line", Duration.millis(5600));
markers.put("Robot Grabs Sled", Duration.millis(8000));
markers.put("And Heads for Home", Duration.millis(11500));
final MediaPlayer mp = new MediaPlayer(m);
mp.setOnMarker((event) -> {
Platform.runLater(() -> {
markerText.setText(event.getMarker().getKey());
});
});
final MediaView mv = new MediaView(mp);
 
Search WWH ::




Custom Search