AVAudioSession操作声音输出
我使用AVSoundSession
来configuration声音, AVAudioPlayer
播放不同的声音。 我搜查了很多,找不到任何东西。 我怎样操纵输出源?
我需要一个在我的SoundManager
中的方法,我可以切换电话扬声器和扬声器之间的输出。
success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
使用这个我可以将声音传送到扬声器,但是没有办法将它移动到电话扬声器。 有人可以帮我吗?
所以,我find了解决scheme来处理声音输出。
您可以使用AVAudioSession
初始化声音设置
像这样的东西:
session = [AVAudioSession sharedInstance]; BOOL success; NSError* error; success = [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error]; if (!success) NSLog(@"AVAudioSession error setting category:%@",error); success = [session setMode:AVAudioSessionModeVoiceChat error:&error]; if (!success) NSLog(@"AVAudioSession error setting mode:%@",error); success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error]; [session setPreferredOutputNumberOfChannels:0 error:nil]; if (!success) NSLog(@"AVAudioSession error overrideOutputAudioPort:%@",error); success = [session setActive:YES error:&error]; if (!success) NSLog(@"AVAudioSession error activating: %@",error); else NSLog(@"audioSession active");
同
[session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error];
你设置不要覆盖输出端口。 而你的应用程序与默认扬声器播放。 据我所知,模式AVAudioSessionModeVoiceChat
使用手机扬声器。 这是我的SIP调用者应用程序所需要的。
然后你可以覆盖输出端口
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
我这样做:
- (void) loudSpeakerOn:(BOOL)isLoudSpeaker{ [session setActive:NO error:nil]; BOOL success; NSError* error; success = [session overrideOutputAudioPort:isLoudSpeaker?AVAudioSessionPortOverrideSpeaker:AVAudioSessionPortOverrideNone error:&error]; if (!success) NSLog(@"AVAudioSession error setting category:%@",error); [session setActive:YES error:nil]; }
- iOS AVFoundation:如何从mp3文件中获取作品?
- AVPlayer缓冲,暂停通知和海报框架
- Swift AVCaptureSessionclosures打开button错误:当前不支持多个audio/videoAVCaptureInputs
- AVPlayer失败,AVPlayerItemStatusFailed(OSStatus错误-12983)
- 在forwardPlaybackEndTime之后恢复AVPlayer
- iOS版。 用USB麦克风以96kHzlogging
- 使用AVMutableAudioMix调整资产内曲目的音量
- AVFoundation覆盖另一个video上的alpha通道video?
- 裁剪AVAssetvideo与AVFoundation不工作的iOS 8