How to check if mediaplayer is playing or stopped?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 01:51:32

问题


How can I check whether the mediaplayer is playing or stopped, using Java Media Framework?


回答1:


You can call getState and check against Controller.Started:

if (mediaPlayer.getState() == Controller.Started)



回答2:


// Register ControllerListener :

public class myPlayer implements ControllerListener  {
// ....
    Player player = Manager.createRealizedPlayer(url);
    player.addControllerListener(this);
// ....


// And check for EndOfMedia event in the controllerUpdate method:

    public void controllerUpdate(ControllerEvent event) {
    if (event instanceof EndOfMediaEvent) {
        // Take appropriate action
        }
    }
} // End of class

By checking the state and by listening to EndOfMedia event, one could detect if media is being played or stopped.




回答3:


It seems like a bit changed since the accepted answer. The following works for me:

if(this.player.getStatus() == MediaPlayer.Status.STOPPED){
     // Do something
}


来源:https://stackoverflow.com/questions/10491032/how-to-check-if-mediaplayer-is-playing-or-stopped

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