JavaFX MediaPlayer 在 1 分钟后停止
JavaFX MediaPlayer just stops after 1 minute+
我一直在使用 JavaFX 中的 MediaPlayer class 运行 媒体,直到您关闭应用程序,但 MediaPlayer 在 1 分钟后才停止,文件长 11 分钟。这是我的代码:
@Override
public void start(Stage primaryStage) throws Exception {
FileChooser chooser = new FileChooser();
File file = chooser.showOpenDialog(primaryStage);
Media media = null;
if(file != null) {
media = new Media(file.toURI().toString());
}
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
mediaPlayer.play();
Group root = new Group();
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
Hotfix,尝试在start()
中添加以下代码
primaryStage.setOnCloseRequest(windowEvent -> {
mediaPlayer.stop();
});
我一直在使用 JavaFX 中的 MediaPlayer class 运行 媒体,直到您关闭应用程序,但 MediaPlayer 在 1 分钟后才停止,文件长 11 分钟。这是我的代码:
@Override
public void start(Stage primaryStage) throws Exception {
FileChooser chooser = new FileChooser();
File file = chooser.showOpenDialog(primaryStage);
Media media = null;
if(file != null) {
media = new Media(file.toURI().toString());
}
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
mediaPlayer.play();
Group root = new Group();
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
Hotfix,尝试在start()
primaryStage.setOnCloseRequest(windowEvent -> {
mediaPlayer.stop();
});