Playing Video

Playing video in JavaFX is quite simple. We need to use the same API as we have used in the case of playing Audio files. In the case of playing video, we need to use the MediaView node to display the video onto the scene.

For this purpose, we need to instantiate the MediaView class by passing the Mediaplayer object into its constructor. Due to the fact that, MediaView is a JavaFX node, we will be able to apply effects to it.

In this part of the tutorial, we will discuss the steps involved in playing video media files and some examples regarding this.

Steps to play video files in JavaFX

  1. Instantiate the javafx.scene.media.Media class by passing the location of the audio file in its constructor. Use the following line of code for this purpose.
  2. Pass the Media class object to the new instance of javafx.scene.media.MediaPlayer object.
  3. Invoke the MediaPlayer object's play() method when onReady event is triggered.
  4. Instantiate MediaView class and pass Mediaplayer object into its constructor.
  5. Add the MediaView Node to the Group and configure Scene.

Example


JavaFX Playing Video




Contact US

Email:[email protected]

JavaFX Playing Video
10/30