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 to do it...

  1. Let's first create a class with empty methods, which would represent the main application for launching the application as well as the JavaFX UI:
        public class EmbedAudioVideoDemo extends Application{
          public static void main(String[] args) {
            Application.launch(args);
          }
          @Override
          public void start(Stage stage) {
            //this will have all the JavaFX related code
          }
        }
  1. Create a javafx.scene.media.Media object for the video located at chp9/11_embed_audio_video/sample_video1.mp4:
        File file = new File("sample_video1.mp4");
        Media media = new Media(file.toURI().toString());
  1. Create a new media engine,  javafx.scene.media.MediaPlayer, using the javafx.scene.media.Media object created in the previous step:
 MediaPlayer mediaPlayer = ...

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