判断android后台是否正在播放音乐?

2026年09月16日 20:32
有2个网友回答
网友(1):

通过AudioManager的isMusicActive(),可以判断当前是否有音乐正在播放。

/**
* AudioManager provides access to volume and ringer mode control.
*


* Use Context.getSystemService(Context.AUDIO_SERVICE) to get
* an instance of this class.
*/
public class AudioManager {
...
/**
* Checks whether any music is active.
*
* @return true if any music tracks are active.
*/
public boolean isMusicActive() {
return AudioSystem.isStreamActive(STREAM_MUSIC, 0);
}
...
}

网友(2):

看看任务管理器,播放器有没有在后台运行