How to tell if MediaPlayer is playing?

ⅰ亾dé卋堺 提交于 2019-12-06 14:16:09

问题


How can I tell if javafx.scene.media.MediaPlayer is playing? Preferably without any external imports or additions to the build path. If this is not possible, are there any libraries that I can use that are self-contained? I am installing this software on an ARM CPU so I am trying to make this code as minimalist as possible. I am only going to use this framework to play music files and primarily MP3s. Any suggestions on how I can tell if the player is playing music with this or a different library?


回答1:


if I understood:

mediaPlayer.setOnEndOfMedia(new Runnable() {
    @Override
    public void run() {
        playing = false;
    }
});

mediaPlayer.setOnReady(new Runnable() {
    @Override
    public void run() {
        mediaPlayer.play();
        playing = true;
    }
});

Or

boolean playing = mediaPlayer.getStatus().equals(Status.PLAYING);



回答2:


I may be wrong, but for the boolean it is : Status.READY



来源:https://stackoverflow.com/questions/18340125/how-to-tell-if-mediaplayer-is-playing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!