我正在做一个示例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;
}
}
};
当手机本机相机正在录制视频时,如何获得音频焦点。?