How to check if mediaplayer is playing or stopped?

2019-02-20 08:14发布

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

3条回答
▲ chillily
2楼-- · 2019-02-20 08:30

You can call getState and check against Controller.Started:

if (mediaPlayer.getState() == Controller.Started)
查看更多
Animai°情兽
3楼-- · 2019-02-20 08:39
// 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.

查看更多
聊天终结者
4楼-- · 2019-02-20 08:46

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

if(this.player.getStatus() == MediaPlayer.Status.STOPPED){
     // Do something
}
查看更多
登录 后发表回答