如何判断 MediaPlayer 是否正在播放? [英] How to tell if MediaPlayer is playing?

查看:125
本文介绍了如何判断 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆