java如何在JavaFXMediaPlayer结束时暂停它?
在JavaFX中使用MediaPlayer
和MediaView
播放视频时,当播放机到达视频末尾时,播放机的状态保持在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) 个答案