问题
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