为openTok设置输出扬声器?

时间:2016-09-08 12:50:50

标签: ios objective-c xcode avaudiosession opentok

我尝试与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!

0 个答案:

没有答案