JavaFX video stream error Webview youtube

When I try to load a video in JavaFX Webview, youtube will display an error message when clicking on play, saying "An error occured, please try again later"

I have it:

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 is created in FXML and is not used outside of this method.

Any help would be appreciated! :)

+3


source to share


2 answers


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

See bug report:

This error report is logged on Windows 7.



I tried my old solution:

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

This solution plays videos using YouTube running under the embedded WebView control. And it worked on OS X 10.9, Java 8u20. The program prints blank messages to the console: "Excluded resource locks found" as described in RT-35062, but otherwise appears to have done OK and displayed a video. Thus, I think the potential JVM crash mentioned in RT-35062 is environment specific.

0


source


I'm pretty sure YouTube embed urls cannot be loaded into a WebView like this ...

Try using iframe markup (you can get an example on a regular YouTube page for most videos) with a call to engine.loadContent (). 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 disallow a typo or two in the string literal, I expect it to work.

-1


source







All Articles