Create MediaPlayer : MediaPlayer « JavaFX « Java






Create MediaPlayer

 
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

public class Main extends Application {
  @Override
  public void start(Stage stage) {
    VBox box = new VBox();
    Scene scene = new Scene(box, 200, 200);
    stage.setScene(scene);

    Media media = new Media("video file URI");
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.setAutoPlay(true);

    MediaView mediaView = new MediaView(mediaPlayer);
    ((VBox) scene.getRoot()).getChildren().add(mediaView);

    stage.show();
  }
  public static void main(String[] args) {
    launch(args);
  }
}

   
  








Related examples in the same category

1.Full Screen Video Player
2.Media Player for flv file
3.VideoPlayer 3