如何判断MediaPlayer是否正在播放? [英] How to tell if MediaPlayer is playing?
本文介绍了如何判断MediaPlayer是否正在播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何判断javafx.scene.media.MediaPlayer是否正在播放?最好不要对构建路径进行任何外部导入或添加。如果这是不可能的,那么我可以使用任何自包含的库吗?我正在ARM CPU上安装此软件,所以我试图使这段代码尽可能简化。我只会使用这个框架播放音乐文件,主要是MP3。关于如何判断玩家是否正在使用此库或其他库播放音乐的任何建议?
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?
推荐答案
如果我理解:
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
playing = false;
}
});
mediaPlayer.setOnReady(new Runnable() {
@Override
public void run() {
mediaPlayer.play();
playing = true;
}
});
或
boolean playing = mediaPlayer.getStatus().equals(Status.PLAYING);
这篇关于如何判断MediaPlayer是否正在播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文