JavaFX MediaPlayer Preview

The screenshot below is a preview of a JavaFX MediaPlayer created in Processing4 after adding the javafx.media module to line 1086 of JavaBuild.java and recompiling the editor. The source code and output are shown below:

Source code:

import java.io.File;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

void setup() {
  size(1, 1, FX2D);
  Stage stage = new Stage();
  // **** Replace this with your file path **** //
  String path = "/Users/xxxxxx/Movies/birds.mp4";
  Media media = new Media(new File(path).toURI().toString());
  MediaPlayer mediaPlayer = new MediaPlayer(media);
  MediaView mediaView = new MediaView(mediaPlayer);
  mediaPlayer.setAutoPlay(true);
  mediaView.setLayoutX(10);
  mediaView.setLayoutY(10);
  Group root = new Group();
  root.getChildren().add(mediaView);
  Scene scene = new Scene(root, 500, 400);
  stage.setScene(scene);
  stage.setTitle("Playing video");
  stage.show();
}

void draw(){
}

Output:

2 Likes