How to wait for JavaFx MediaPlayer to finish

前端 未结 1 1439
臣服心动
臣服心动 2021-01-24 22:05

I have a MediaPlayer object which plays a video. When the video is finished playing, I want the program to hide the MediaView and display different Jav

相关标签:
1条回答
  • 2021-01-24 22:53

    Can't find any official documents that mention this but I'm pretty sure the media file is played on a separate thread under the hood by JavaFX so that it doesn't block the UI thread. This is why you need to use MediaPlayer.setOnEndOfMedia:

    view.setMediaPlayer(player);
    
    player.setOnEndOfMedia(() -> {
        view.setVisible(false); 
    });    
    
    player.play();
    
    0 讨论(0)
提交回复
热议问题