0

I have created a youtube video player with a JavaFX application and I want to launch this application with a play button on my main frame. I have created a play button an created its actionlistener to launch the application. The app launches without any problem but when I try to close it, the window closes but the video keeps on playing in the background. How can completely shut down the launched application( video player ) , so it does not continue playing the video. The code for my app is here

public class YoutubeVideoPlayer extends Application {
   public static void main(String[] args) {
      launch(args);
   }
   @Override
   public void start(Stage primaryStage) throws Exception{
        WebView webView = new WebView();
        webView.getEngine().load("https://www.youtube.com/embed/6uL3SHfllh8");

        webView.setPrefSize( 300 , 300);

        primaryStage.setScene( new Scene( webView ) );
        primaryStage.show();

        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
            @Override
            public void handle(WindowEvent we) {
               Platform.setImplicitExit(true);
               primaryStage.close();
               Platform.exit();
            }
        });        
   }
}

Again, I want the YoutubeVideoPlayer to completely shut down ( stop the video from playing ) without closing the main application. I do not have much knowledge of JavaFX so I would really appreciate if you could explain your answer. Thanks...

Ata Atasoy
  • 23
  • 6
  • The player creates a separate thread in order to not freeze the gui on the main-thread. Try primaryStage.close() before platform.exit() – Joel Jul 23 '18 at 19:54
  • I tried your answer but it didn't work. Any other ideas other than System.exit(0) ? – Ata Atasoy Jul 23 '18 at 20:05

0 Answers0