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
}