3

I have a simple javaFX application that loads a webpage in a WebView componant.

StackPane root = new StackPane();
Scene scene = new Scene(root, 80, 20);
browser = new WebView();
webEngine = browser.getEngine();

webEngine.load("test.html");
root.getChildren().add(browser);
jfxPanel.setScene(scene);

This works fine and test.html can be seen. The issue is with the HTML5 video on the page.

<video width="320" height="240" controls="controls">
    <source src="http://upload.wikimedia.org/wikipedia/commons/7/79/Big_Buck_Bunny_small.ogv" type="video/ogg" />
    Your browser does not support the video tag.
</video>

The page works in Chrome 16, but in the java application you can only see the controls and clicking play does nothing. I assume the WebEngine allows HTML5 as the controls appear and the text inside the <video></video> tags isn't output.

Can anyone shed some light on what I doing wrong?

Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99

1 Answers1

8

You are encountering a codec issue.

From the JavaFX FAQ question 7, JavaFX (as of 2.0.2) only supports flv videos encoded using the on2 vp6 codec.

Additional codec support is scheduled for future releases. The relevant feature request is RT-18296 (login required, but anybody can sign up to view the JavaFX issue database and create feature requests, vote for issues or post comments).

A related StackOverflow question provides a summary of considerations for playing video in JavaFX 2.1 (including a JavaFX WebView).

To demonstrate a html5 video tag and video playback within a JavaFX WebEngine, run the following code, which plays an Oracle supplied vp6 encoded video.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebViewVideo extends Application {
  public static void main(String[] args) { Application.launch(args); }
  @Override public void start(Stage primaryStage) {
    WebView root = new WebView();
    root.getEngine().loadContent(
      "<video width='320' height='240'controls='controls'>" +
        "<source src='http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv'/>" + 
        "Your browser does not support the video tag." + 
      "</video>");
    primaryStage.setScene(new Scene(root, 340, 260));
    primaryStage.show();
  }
}
Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Then I suppose it's safe to say that JavaFX doesn't really support HTML5. As HTML5 shouldn't in itself care what codecs JavaFX can/cannot support, but the OS. Luckily as at JavaFX 2.1, there is now support for H.264 (MP4) video, so this makes things much less painful. :) – Glstunna Apr 18 '12 at 20:42
  • Can you use the loop attribute in the video tag? When I use the loop attribute, it won't loop :( – Someone13 May 30 '14 at 11:25
  • To answer my question, it was the version of JavaFX I was using. I upgraded to Java8 and everything is fine. mp4 videos work, and looping does as well. – Someone13 May 31 '14 at 06:02