Java Reference
In-Depth Information
16-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 16-2 Playing Video");
primaryStage.centerOnScreen();
primaryStage.initStyle(StageStyle.TRANSPARENT);
final Group root = new Group();
final Scene scene = new Scene(root, 540, 300,
Color.rgb(0, 0, 0, 0));
// 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);
// allow the user to see the progress of the video
playing
progressSlider = createSlider(scene);
root.getChildren().add(progressSlider);
Search WWH ::




Custom Search