Using HTML5 Video Tags in JavaFX applications

I have a simple JavaFX application that loads a web page in the WebView component

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);

That's good. You can see test html. The problem is the HTML 5 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>

This page is applicable to chrome 16, but in Java applications, you can only see the controls. Clicking "play" will not perform any action I assume that webengine allows HTML5 to appear as a control, and the text is in < video > < / video > Labels are not output

Can anyone make it clear that I did wrong?

Solution

You have encountered a codec problem

Starting from JavaFX FAQ question 7, JavaFX (starting from 2.0.2) only supports flv video encoded with on2 VP6 codec

Additional codec support is scheduled for future releases The related function request is rt-18296 (login is required, but anyone can register to view the JavaFX problem database and create a function request, vote to select a problem or comment)

Related stackoverflow issues provide summary of considerations for playing video in JavaFX 2.1 (including JavaFX WebView)

To demonstrate HTML5 video tagging and video playback in JavaFX webengine, run the following code, which plays the VP6 encoded video provided by Oracle

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();
  }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>