关闭阶段JavaFX后如何停止WebEngine? [英] How to stop WebEngine after closing stage JavaFX?
问题描述
当我用WebEngine创建一个播放YouTube视频的新舞台时,我关闭它之后--Youtube继续播放背景音乐。如果我使用Platform.exit - 它关闭我所有的JavaFX应用程序,但我想关闭仅为YouTube创建的阶段。
When i create new stage with WebEngine that playing video from YouTube, after i close it - Youtube keeps playing on backgroung. If i use "Platform.exit" - its close all my JavaFX App, but i want to close only stage that been created for YouTube.
这是我的YouTube课程玩家:
This is my class for YouTube player:
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播放器舞台正在创作之后我点击'mainstage'中的按钮:
My Youtube player stage is creating after i clicking on button in 'mainstage':
b1.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
new YouTube_player(url_video_p1);
}
});
推荐答案
你无法处理webengine你能做的唯一事情做的是将webEngine的内容设置为 null
You cant dispose the webengine the only thing that you can do is to set the content of the webEngine to null
webView.getEngine() .load(null);
这篇关于关闭阶段JavaFX后如何停止WebEngine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!