当我使用 WebEngine 创建新阶段以播放来自 YouTube 的视频时,在我关闭它后 - Youtube 继续在背景上播放。如果我使用“Platform.exit” - 它关闭了我所有的 JavaFX 应用程序,但我只想关闭为 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);
}
});