AVAudioSession*audioSession=[AVAudioSessionsharedInstance];
//1.设置为播放和录音状态,以便可以在录制完之后播放录音AVAudioSessionCategoryAmbient AVAudioSessionCategoryPlayAndRecord
[audioSessionsetCategory:AVAudioSessionCategoryPlayAndRecorderror:nil];
[audioSessionsetActive:isActiveerror:nil];
[audioSessionoverrideOutputAudioPort:AVAudioSessionPortOverrideSpeakererror:nil];
//2.这个方法相当于上面方法的和但是比overrideOutputAudioPort时效性更长
//[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
UInt32doChangeDefaultRoute =1;
//3.下面方法相当于overrideOutputAudioPort但实效性更长会影响其他应用音频的使用
//kAudioSessionProperty_OverrideAudioRoute kAudioSessionProperty_OverrideCategoryDefaultToSpeaker
AudioSessionSetProperty(
kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
sizeof(doChangeDefaultRoute),
&doChangeDefaultRoute
);
//加两个地址
http://blog.csdn.net/xy5811/article/details/8563137
https://developer.apple.com/library/content/qa/qa1754/_index.html
网友评论