3

When I try to load a video into JavaFX Webview the youtube will display an error message when play is pressed saying: "An error occurred, please try again later"

I have this:

private void change(final Pattern pattern) {
    nameLabel.setText(pattern.getName());
    final WebEngine engine = view.getEngine();
    final String code = "YME_DYsmBpY";
    engine.load("http://www.youtube.com/embed/" + code + "?rel=0;3&autohide=1&showinfo=0");
}

The WebView (view) is created in FXML and is not used outside of this method.

Any help would be appreciated! :)

2 Answers2

0

Although playing YouTube videos using JavaFX used to work in earlier JavaFX versions, I don't believe it works in the current JavaFX version (8u25) on all platforms.

See related bug report:

The above bug report is logged against Windows 7.

I tried my old solution to:

The code for this solution is in the linked question and is very similar to the code in your question.

This solution plays a video using YouTube running under an embedded WebView control. And that worked on OS X 10.9, Java 8u20. The program output to the console weird messages: "Outstanding resource locks detected" as described in RT-35062, but otherwise seemed to execute OK and displayed the video fine. So I guess the potential JVM crash referenced in RT-35062 is environment specific.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406
-1

I'm pretty sure YouTube embed URLs can't be loaded into a WebView like that...

Try using the iframe markup (you can get an example on the regular YouTube page for most videos) with a call to engine.loadContent() instead. For example:

engine.loadContent("<html><body><iframe width=\"1000\" height=\"500\" " +
            "src=\"http://www.youtube.com/embed/" + code + "?rel=0;3&amp;autohide=1&amp;showinfo=0\" frameborder=\"0\" ></iframe></body></html>");

I haven't tested the snippet above, but barring a typo or two in the string literal I expect it to work.

gmlwd6
  • 1
  • 2