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

**URL:** <https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173>\
**Category:** Coding Questions\
**Created:** [May 12, 2019, 3:00pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173 "2019-05-12T15:00:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![94matheus](https://avatars.discourse-cdn.com/v4/letter/9/c57346/32.png) [@94matheus](https://discourse.processing.org/u/94matheus)\
**Post date:** [May 12, 2019, 3:00pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/1 "2019-05-12T15:00:28Z")

</div>

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) {

      PApplet.main("UsingProcessing");
   }

   public void settings() {

	  size(1100, 618,FX2D);
   }

   public void setup() {

	  try {
		 
	      Field field = PSurfaceFX.class.getDeclaredField("stage");
	      field.setAccessible(true);
	      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"));
          viewer.setPreserveRatio(true);
	    
	      StackPane root = new StackPane();
	      root.getChildren().add(viewer);
	
	      Scene scenes = new Scene(root, 1100, 618, Color.TRANSPARENT);
	      stage.setScene(scenes);
	      stage.setTitle("OBSV.CamFeed.6°07'08.3\"S 12°23'51.5\"E");
	      stage.setFullScreen(false);
	      stage.show();
	      player.setStartTime(duration); 
	      player.setCycleCount(MediaPlayer.INDEFINITE);
	      player.play();
	  } 

	  catch(Exception e) {

	      e.printStackTrace();
	  }
   }

   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!
   }
}
```

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 12, 2019, 9:46pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/2 "2019-05-12T21:46:24Z")

</div>

Hi,

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

- [https://processing.org/reference/libraries/video/index.html](https://processing.org/reference/libraries/video/index.html)

---

<div class="post-metadata">

**Author:** ![94matheus](https://avatars.discourse-cdn.com/v4/letter/9/c57346/32.png) [@94matheus](https://discourse.processing.org/u/94matheus)\
**Post date:** [May 12, 2019, 10:23pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/3 "2019-05-12T22:23:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 16, 2019, 1:30pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/4 "2019-05-16T13:30:01Z")

</div>

Were you able to resolve this?

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

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [May 16, 2019, 1:45pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/5 "2019-05-16T13:45:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![94matheus](https://avatars.discourse-cdn.com/v4/letter/9/c57346/32.png) [@94matheus](https://discourse.processing.org/u/94matheus)\
**Post date:** [May 17, 2019, 2:11am UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/6 "2019-05-17T02:11:11Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![94matheus](https://avatars.discourse-cdn.com/v4/letter/9/c57346/32.png) [@94matheus](https://discourse.processing.org/u/94matheus)\
**Post date:** [May 17, 2019, 2:12am UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/7 "2019-05-17T02:12:28Z")

</div>

@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…

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [May 17, 2019, 8:13am UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/8 "2019-05-17T08:13:27Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![94matheus](https://avatars.discourse-cdn.com/v4/letter/9/c57346/32.png) [@94matheus](https://discourse.processing.org/u/94matheus)\
**Post date:** [May 17, 2019, 1:37pm UTC](https://discourse.processing.org/t/solved-while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-for-example-appear-in-front-of-it/11173/9 "2019-05-17T13:37:16Z")

</div>

[https://stackoverflow.com/questions/56095171/while-using-javafx-for-playing-a-video-how-can-i-make-a-rect-processing-lib](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!
