Android获取音频焦点
/**
* 夺取或释放音频焦点
* @param audioManager
* @param bMute
*/
private void muteAudioFocus(AudioManager audioManager, boolean bMute) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
RLog.d("AudioRecordManager", "muteAudioFocus Android 2.1 and below can not stop music");
} else {
if (bMute) {
audioManager.requestAudioFocus(this.mAfChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
} else {
audioManager.abandonAudioFocus(this.mAfChangeListener);
this.mAfChangeListener = null;
}
}
}
AudioManager.AUDIOFOCUS_GAIN
获取后不release,需要手动release
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
临时获取,使用后release
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/25/android-get-audio-focus/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Android获取音频焦点
/**
* 夺取或释放音频焦点
* @param audioManager
* @param bMute
*/
private void muteAudioFocus(AudioManager audioManager, boolean bMute) {
if ……
文章目录
关闭
共有 0 条评论