JavaFX MediaPlayer在1分钟后停止

时间:2015-02-15 15:58:01

标签: java javafx javafx-2 javafx-8

我正在使用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();
    }

1 个答案:

答案 0 :(得分:2)

修补程序,请尝试在start()

中添加以下代码
primaryStage.setOnCloseRequest(windowEvent -> {
    mediaPlayer.stop();
});