Skip to content

Using JavaFX in processing applet #4750

@jej

Description

@jej

Hi,
I want to use javafx.scene.media.MediaPlayer to play video/audio in the processing applet. To play audio it works without problem and hacks, but to play videos I need to hack processing. I struggled to find a clean solution but no result...

I need to get the StackPane created by PSurfaceFX, but this element is not exposed. So I modified /core/src/processing/javafx/PSurfaceFX.java (https://github.com/jej/processing/commit/6a72a99e355ef7c93b1f9778f03c0c6660116ff7)

public class PSurfaceFX implements PSurface {

  static StackPane stackPane;  // was a local field in start()

.../...

  public StackPane getStackPane() {
      return stackPane;
  }

.../...

}

So now I can play videos or draw any(fx)thing in a FX2D applet with:

public void playVideo() {
   PSurfaceFX surface = (PSurfaceFX) getSurface();
   Media media = new Media("file:///pathtofile.flv");
   MediaPlayer player = new MediaPlayer(media);
   MediaView mediaView = new MediaView(player);
   surface.getStackPane().getChildren().add(mediaView);
   player.play();
}

Do you know a better solution to do that without processing modification?

If not, do you think this solution is fine?

J.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions