O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The important classes, in the javafx.scene.media package for media playback are as follows:

  • Media: This represents the source of the media, that is, either the video or audio. This accepts the source in the form of HTTP/HTTPS/FILE and JAR URLs.
  • MediaPlayer: This manages the playback of the media.
  • MediaView: This is the UI component that allows viewing the media. 

There are a few other classes, but we haven't covered them in this recipe. The media-related classes are in the javafx.media module. So, do not forget to require a dependency on it, as shown here:

module gui{
  requires javafx.controls;
  requires javafx.media;
  opens com.packt;
}

In this recipe, we have a sample video at chp9/11_embed_audio_video/sample_video1.mp4

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required