[SOLVED] While using Javafx for playing a video, how can i make a "rect", for example, appear in front of it?

Hi! I’m using PApplet inside Eclipse (A college assignment requires that we use Processing IDE but I need some of Java functions to make it work the way I envision it) and everytime a video starts playing (through javafx) it takes over the whole program screen.

Even though I call a rectangle, for exemple, after I call the video to start, it still takes over the entire screen and I can’t see this rectangle. How can I solve this?

public class UsingProcessing extends PApplet {

   String Dir = System.getProperty("C:\\Users\\Matheus\\eclipse-workspace\\Narraint");
   Stage stage;

   ZonedDateTime now = ZonedDateTime.now();
   LocalDateTime startOfDay = now.toLocalDate().atStartOfDay();
   java.time.Duration d = java.time.Duration.between(startOfDay,now);
   javafx.util.Duration duration = new javafx.util.Duration( d.toMillis());

   public static void main(String[] args) {


   public void settings() {

	  size(1100, 618,FX2D);

   public void setup() {

	  try {
	      Field field = PSurfaceFX.class.getDeclaredField("stage");
	      stage = (Stage)field.get(surface);
	      File f = new File(Dir, "narrativas.mp4");
	      Media media = new Media(f.toURI().toURL().toString());
	      javafx.scene.media.MediaPlayer player = new javafx.scene.media.MediaPlayer(media);
	      MediaView viewer = new MediaView(player);
	      DoubleProperty width = viewer.fitWidthProperty();
          DoubleProperty height = viewer.fitHeightProperty();
          width.bind(Bindings.selectDouble(viewer.sceneProperty(), "width"));
          height.bind(Bindings.selectDouble(viewer.sceneProperty(), "height"));
	      StackPane root = new StackPane();
	      Scene scenes = new Scene(root, 1100, 618, Color.TRANSPARENT);
	      stage.setTitle("OBSV.CamFeed.6°07'08.3\"S 12°23'51.5\"E");

	  catch(Exception e) {


   public void draw() {

      rect(30, 20, 80, 50); //Just for testing, if anything can show up in
                           //front of the video then my problem is solved!
1 Like


Just a simple question, why don’t you use the Video library for Processing ?

1 Like

Hi there,

It is because my video file is 24hours long! The processing video library won’t play it, I tried a bunch of times. On the other hand, javafx starts playing it immediately, even when run directly inside processing!

Were you able to resolve this?

The thing that jumps out at me as a possibility is your use of Stage.

1 Like

Have you tried the v2 beta of the Video library? JavaFX also has GStreamer under the hood.

1 Like

@jeremydouglass Not yet! Oh and thanks, i’ll keep fiddling with Stage but the thing is, i need to separate the object from the background, and they both need to be separated from the video. I actually found out how to make the background transparent but it makes everything in it also transparent. I need to have them on a diferent Stage perhaps?

@neilcsmith The thing is that now i actually wrote another part of my project that works with java fx so i don’t think i can go back using the video library, even if it works…

Fair enough! I think you might have difficulties, but the key thing I’d suggest looking at is not using reflection to get the Stage or creating your own StackPane. Try getNative() on the surface, which should give you the canvas ( https://github.com/processing/processing/blob/master/core/src/processing/javafx/PSurfaceFX.java#L126 ). Then add the movie player node to the StackPane the canvas is already in? Its parent? You’ll have to remove and re-add the canvas to get it on top I think. This would also depend on the canvas actually having a transparent background.

https://stackoverflow.com/questions/56095171/while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-processing-lib Problem solved! Thank you all for your help!