Saad Saad - 1 year ago 270
Java Question

JavaFx Webview not loading html5 video on localhost server

I managed to run simple JavaFx Webview app rendering an html file at a localhost running on micro-services Spark web framework that uses in embedded jetty container what my issue is the JavaFx Webview is not recognizing the video file source of the html5 video tag while using chrome, ie, and other major browsers the page renders perfectly and the video file is working.

I don't now if it's a bug or is that I have messed something.

here is a working snap of my issue:

Workspace files lyaout:

├── public
| └── index.html
| └── video.mp4
└── src
└── main
| └── java
| └── com
| └── mycompany
| └──
| └──
└── pom.xml



package com.mycompany;

import spark.Spark;

public class SparkTest {
public static void main(String[] args) {
Spark.get("/run", (request, response) -> "Spark is Runnig");

package com.mycompany;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class MainTest extends Application {
public void start(Stage stage) throws Exception {
StackPane root = new StackPane();
WebView view = new WebView();
Scene scene = new Scene(root, 800, 600);

public static void main(String[] args) throws IOException {


<!DOCTYPE html>
<h1>html5 video</h1>
<video controls preload="auto" width="640" height="480">
<source src="video.mp4" type='video/mp4'>

here you can find .mp4 video file

Answer Source

After my last comment I debugged and tried a little more and found the following:

The WebView browser tries to load the file from spark by using the range http header, to load in chunks; from the spark server logs I can see the following request:

GET // 
X-Playback-Session-Id: 1178DCF3-69C3-4A8E-B5F6-4FD24AD3F421 
Range: bytes=0-1 
Accept: */* 
User-Agent: AppleCoreMedia/ (Macintosh; U; Intel Mac OS X 10_11_6; de_de) 
Accept-Language: de-de
Accept-Encoding: identity 
Connection: keep-alive

Spark at the moment does not support use of the range header for large files, there is an open issue concerning that missing feature.

So you did not mess something, it's just a missing feature from spark, combined with the fact that WebView does not load the whole file in one piece, I suppose that's because of the data being media served over the net.

Sp your best solution might be looking for a different server to serve your media. Or try to get this feature into spark by either contributing or asking Per Wendel if this could be integrated.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download