0

Is there is any way to play Youtube videos on JavaFX Application? I was trying this-

public class YoutubeVideoPlayer extends Application
{
    @Override
    public void start(Stage stage) throws Exception
    {
        WebView webview = new WebView();
        webview.getEngine().load("http://www.youtube.com/embed/_3op5hukpIE?autoplay=1");
        webview.setPrefSize(640, 390);

        stage.setScene(new Scene(webview));
        stage.show();
    }

    public static void main(String[] args)
    {
        launch(args);
    }
}

I don't know how, but once it worked fine. But every time it is showing me an error message:

An error occured. Please try again later.

Can anyone explain how did it work and how can I make it work again?

Rana Depto
  • 721
  • 3
  • 11
  • 31

1 Answers1

1

This code is not working when I was running this on IDE(Eclipse, NetBeans or IntelliJ). But when I am Exporting this from Eclipse IDE as "Runnable JAR file", and running the Jar file, it's working perfectly. It seems, it's just not running on IDE.

Rana Depto
  • 721
  • 3
  • 11
  • 31
  • 1
    Perhaps your IDE is set to use a different JRE version than when you run your application as a JAR file. See some of the update info in the answer to: [Play a video using javafx](http://stackoverflow.com/a/18761332/1155209). "Some versions of JavaFX 8 are unable to play back youtube video content. Currently, for instance, Java 8u66 cannot playback youtube video content, but Java 8u72 early access release can." – jewelsea Apr 15 '16 at 17:22
  • Thanks @jewelsea, I read your answer. In fact, I took this code snippet from your answer. It's an honor to find you here. I tried 8u72. Now I am running 8u102. Still it can't play. You mentioned that you ran this on Mac and it ran successfully. But as far I know, the people who are using Windows, are facing this problem. And unfortunately I am also using Windows. – Rana Depto Apr 15 '16 at 18:12
  • Are you sure you are running 8u102? As far as I can see, no such Java version exists and the latest released version is [8u77](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). – jewelsea Apr 15 '16 at 18:20
  • I downloaded [8u102](https://jdk8.java.net/download.html). After reading your comment I uninstalled all the versions and install **8u77** again and now it's working. Now I understand how did this worked, when I installed 8u77 version, it started running perfectly, but when I installed 8u102 assuming as latest version(!), youtube video stopped playing again. Thanks again for clearing this. – Rana Depto Apr 15 '16 at 19:48