3-2. Playing Video

Problem

You want to view a video file complete with controls to play, pause, stop, and seek.

Solution

Create a video media player by utilizing the following classes:

  • javafx.scene.media.Media
  • javafx.scene.media.MediaPlayer
  • javafx.scene.media.MediaView

The following code is an implementation of a JavaFX basic video player:

public void start(final Stage primaryStage) {     primaryStage.setTitle("Chapter 3-2 Playing Video");     ... setting up the stage     // rounded rectangle with slightly transparent             Node applicationArea = createBackground(scene);     root.getChildren().add(applicationArea);     // allow the user to drag window on the desktop     attachMouseEvents(scene, primaryStage);     // allows the user ...

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.