关闭阶段JavaFX后如何停止WebEngine?

当我使用WebEngine创建播放YouTube视频的新舞台时,关闭它后-Youtube会继续在backgroung上播放.如果我使用“ Platform.exit”-它会关闭我的所有JavaFX App,但我只想关闭为YouTube创建的阶段.

这是我针对YouTube播放器的课程:

public class YouTube_player  {
    public YouTube_player(String url) {
        final Group root = new Group();
        Scene scene = new Scene(root, 820, 480);

        final Stage stage = new Stage();
        final WebView webView = new WebView();
        final WebEngine webEngine = webView.getEngine();
        webEngine.loadContent(url);
        root.getChildren().add(webView);
        stage.centerOnScreen();

        stage.setScene(scene);
        stage.show();
        stage.setOnCloseRequest(new EventHandler<WindowEvent>(){

            @Override
            public void handle(WindowEvent event) {
              //What i should put here to close only this stage.
              //Platform.exit - closes all my stages.
              //webEngine.getLoadWorker().cancel(); - dont stop Youtube )))
            }
        });

    }
}

我在“主舞台”中单击按钮后,正在创建我的Youtube播放器舞台:

b1.setOnAction(new EventHandler<ActionEvent>() {
    @Override public void handle(ActionEvent event) {
        new YouTube_player(url_video_p1);
    }
});

解决方法:

您只能将webEngine的内容设置为null,否则无法处置该Webengine.

webView.getEngine().load(null);

上一篇:PWM点灯,我们是专业的


下一篇:HTML中的JavaFX组件?