Module javafx.media

Class MediaView

java.lang.Object
javafx.scene.Node
javafx.scene.media.MediaView
All Implemented Interfaces:
Styleable, EventTarget

public class MediaView extends Node
A Node that provides a view of Media being played by a MediaPlayer.

The following code snippet provides a simple example of an Application.start() method which displays a video:


 public void start(Stage stage) {
     // Create and set the Scene.
     Scene scene = new Scene(new Group(), 540, 209);
     stage.setScene(scene);

     // Name and display the Stage.
     stage.setTitle("Hello Media");
     stage.show();

     // Create the media source.
     String source = getParameters().getRaw().get(0);
     Media media = new Media(source);

     // Create the player and set to play automatically.
     MediaPlayer mediaPlayer = new MediaPlayer(media);
     mediaPlayer.setAutoPlay(true);

     // Create the view and add it to the Scene.
     MediaView mediaView = new MediaView(mediaPlayer);
     ((Group) scene.getRoot()).getChildren().add(mediaView);
 }
 
The foregoing code will display the video as:

Hello Media
Since:
JavaFX 2.0