有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在JavaFXMediaPlayer结束时暂停它?

在JavaFX中使用MediaPlayerMediaView播放视频时,当播放机到达视频末尾时,播放机的状态保持在PLAYING,这在^{}上有记录:

Reaching the end of the media (or the stopTime if this is defined) while playing does not cause the status to change from PLAYING. Therefore, for example, if the media is played to its end and then a manual seek to an earlier time within the media is performed, playing will continue from the new media time.

我试着在到达终点时暂停:

mediaPlayer.setOnEndOfMedia(() -> {
    mediaPlayer.pause();
});

但它仍然处于PLAYING模式。此版本包含调试信息:

mediaPlayer.setOnEndOfMedia(() -> {
    System.out.println("end of media");
    System.out.println(mediaPlayer.getStatus());
    mediaPlayer.pause();
    Platform.runLater(() -> System.out.println(mediaPlayer.getStatus()));
});

当控制台上的输出为:

end of media
PLAYING
PLAYING

你知道这是为什么,或者如何迫使媒体播放器进入PAUSE状态吗

我调试了两种情况:普通的暂停和视频结束时的暂停,它们的行为与调用^{}的行为相同,这是一种本机方法,因此,我撞到了墙上


共 (0) 个答案