无法使用javaFx Webview在网页中显示视频(视频在给定的URL上实时显示) [英] Unable to display video in webpage using javaFx Webview (video is live on the given url)

查看:380
本文介绍了无法使用javaFx Webview在网页中显示视频(视频在给定的URL上实时显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JavaFX Webview中显示实时网页.网页包含一个视频,但是该视频无法在javaFX webview中播放.

I am trying to display a live webpage in JavaFX Webview . Web page contains a video but that video not playing in javaFX webview .

以下是我正在使用的comple代码,其中还包含我的网页的实时网址. 我希望在JavaFX Web视图中的视频应该通过显示的实时网页播放.

Following is the comple code i am using it also contains the live url of my webpage. I want in my JavaFX web view video should be played through displayed live web page.

package webviewbrowser;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.List;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

 public class WebViewBrowser extends Application {

 @Override public void start(Stage primaryStage) throws Exception {
    Pane root = new WebViewPane();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   double width = screenSize.getWidth();
   double height = screenSize.getHeight();
    primaryStage.setScene(new Scene(root, width, height));
    primaryStage.show();
  }

public static void main(String[] args) {
    launch(args);
}

public class WebViewPane extends Pane {

    public WebViewPane() {
        VBox.setVgrow(this, Priority.ALWAYS);
        setMaxWidth(Double.MAX_VALUE);
        setMaxHeight(Double.MAX_VALUE);

        WebView view = new WebView();
        view.setMinSize(500, 400);
        view.setPrefSize(500, 400);
        final WebEngine eng = view.getEngine();
        try
        eng.load("http://techyadesh.com/video.php");
        }
        catch(Exception ex)
        {

        }

        GridPane grid = new GridPane();
        grid.setVgap(5);
        grid.setHgap(5);
        GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
        grid.getColumnConstraints().addAll(
                new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
                new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
        );
       // grid.getChildren().addAll(locationField, goButton, view);
         grid.getChildren().addAll( view);
        getChildren().add(grid);
    }

    @Override protected void layoutChildren() {
        List<Node> managed = getManagedChildren();
        double width = getWidth();
        double height = getHeight();
        double top = getInsets().getTop();
        double right = getInsets().getRight();
        double left = getInsets().getLeft();
        double bottom = getInsets().getBottom();
        for (int i = 0; i < managed.size(); i++) {
            Node child = managed.get(i);
            layoutInArea(child, left, top,
                           width - left - right, height - top - bottom,
                           0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER);
        }
    }
}

}

推荐答案

您写的内容似乎运行良好.我在javafx 13上尝试了它,然后才起作用. 在将其粘贴到stackoverflow中时,您在几个地方错过了括号.除此之外,我没有看到任何错误.只需升级您的javafx,它就可以正常工作.

It seems to be working fine what you wrote. I tried it on javafx 13 and it just worked. You missed brackets in a couple of places while pasting it in stackoverflow. Other than that I didn't see any mistake. Just upgrade your javafx and it should work.

这是一个工作示例,其中包含您的确切代码

Here is a working example with your exact code

https://github.com/shashaanktulsyan/java-javafx-maven-learning-tips/tree/master/nu-sharabheshwara-adesh_singh-webview

mvn javafx:run 应该工作.

这篇关于无法使用javaFx Webview在网页中显示视频(视频在给定的URL上实时显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆