我目前正在制作一个简单的HttpHandler来显示mp4视频的内容(在https网址中)。在我的浏览器中它工作,一切都显示应该,但当我将这个http网址传递给javafx媒体播放器时,它给了我错误:
Nov 09, 2015 10:02:13 PM sun.net.httpserver.ExchangeImpl sendResponseHeaders
WARNING: sendResponseHeaders: being invoked with a content length for a HEAD request
为什么会出现此错误? HandlerCode:
@Override
public void handle(HttpExchange exchange)
throws IOException
{
Headers h = exchange.getResponseHeaders();
h.add("viewport", "width=device-width");
String res = "<html><body><video controls autoplay name=\"media\"><br><source src=\"https://longurl.mp4\" type=\"video/mp4\"></video></body></html>";
exchange.sendResponseHeaders(200, res.length());
System.out.println("ResponseHeaders sent with " + res.length());
exchange.getResponseBody().write(res.getBytes());
exchange.getResponseBody().flush();
exchange.getResponseBody().close();
System.out.println("Sent data");
}
MediaPlayer线程:
private void init(String source) //new URL("http://localhost:8000/stream").toURI().toASCIIString()
{
System.out.println("ttttt T_T");
Platform.runLater(new Runnable()
{
@Override
public void run()
{
media = new Media(source);
mediaPlayer = new MediaPlayer(media);
mediaView = new MediaView(mediaPlayer);
mediaPlayer.setOnReady(new Runnable()
{
@Override
public void run()
{
mediaPlayer.play();
}
});
root.getChildren().add(mediaView);
}
});
}
控制台输出:
ttttt T_T
Nov 09, 2015 10:02:13 PM sun.net.httpserver.ExchangeImpl sendResponseHeaders
WARNUNG: sendResponseHeaders: being invoked with a content length for a HEAD request
ResponseHeaders sent with 961
ResponseHeaders sent with 961
Sent data
ResponseHeaders sent with 961
Sent data
答案 0 :(得分:0)
在早期版本中,Java无法很好地处理https网址。这从JDK 1.8.0_76开始修复。但目前还没有公开发布,只有早期的访问构建。