Android获取音频焦点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* 夺取或释放音频焦点
* @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

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :