我尝试与openTok
进行音频/视频通话,可以更改输出扬声器。我希望将其设置为默认的耳机,并使用该代码。
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
self.audioSpeakerButton.selected =true;
我第一次使用AVAudioPlayer
播放铃声,代码如下:
audioPLayer =[[AVAudioPlayer alloc]initWithContentsOfURL:pewPewURL fileTypeHint:@"mp3" error:nil];
audioPLayer.numberOfLoops=-1;
[audioPLayer prepareToPlay];
[audioPLayer play];
声音来自耳机,这很好。
当第二个用户连接后我停止audioPlayer
,但声音来自扬声器,这是坏的。
- (void)subscriberDidConnectToStream:(OTSubscriberKit *)subscriber
{
[audioPLayer pause];
[audioPLayer stop];
audioPLayer = nil;
}
我使用该按钮动作来改变输出扬声器,但没有任何改变。
-(void)audioSpeakerButtonAction{
if (![self.audioSpeakerButton isSelected]) {
NSError *error = nil;
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error];
self.audioSpeakerButton.selected = YES;
} else {
NSError *error = nil;overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
self.audioSpeakerButton.selected = NO;
}
}
I will appreciate any help. Thanks in advance!