我正在做一个示例 Voip 应用程序。当用户使用默认相机应用程序录制视频时,并且传入的 voip 呼叫来了,我想停止视频录制以将音频焦点转移到我的应用程序。
mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
private OnAudioFocusChangeListener mAudioFocusListener = new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
Logger.d(TAG, "--------Audio Focus change: " + focusChange);
switch(focusChange){
case AudioManager.AUDIOFOCUS_GAIN:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_GAIN" );
break;
case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_GAIN_TRANSIENT" );
break;
case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK" );
break;
case AudioManager.AUDIOFOCUS_LOSS:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_LOSS" );
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_LOSS_TRANSIENT" );
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK" );
break;
case AudioManager.AUDIOFOCUS_REQUEST_FAILED:
Logger.d(TAG, "--------Focus change: AUDIOFOCUS_REQUEST_FAILED" );
break;
}
}
};
手机原生摄像头录制视频时如何获得音频焦点?