我正在使用JavaFX中的MediaPlayer类来一直运行媒体,直到您关闭应用程序,但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();
}
答案 0 :(得分:2)
修补程序,请尝试在start()
primaryStage.setOnCloseRequest(windowEvent -> {
mediaPlayer.stop();
});