AVAudioPlayer автоматически останавливается, когда приложение присоединяется к каналу agora.io - PullRequest
2 голосов
/ 07 апреля 2020

Я добавляю звук, когда пользователь нажимает кнопку вызова / joinChanne (Agora) в моем приложении.

    [self.agoraKit joinChannelByToken:self.userManager.agoraToken channelId:self.userManager.channelName info:nil uid:[self.userManager.UID integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"ringing-sound-jalebi" ofType:@"mp3"];
        NSURL *soundFileURL = [NSURL fileURLWithPath:path];
        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
        self.audioPlayer.delegate = self;
       [self.audioPlayer play];
     }];

Но я получаю "AVAudioSession.mm:997:-[AVAudioSession setActive: withOptions: error:]: деактивировать аудиосеанс с запущенным вводом / выводом. Все операции ввода / вывода должны быть остановлены или приостановлена ​​до деактивации аудио сеанса "ошибка. Может кто-нибудь, пожалуйста, помогите мне решить эту проблему

1 Ответ

3 голосов
/ 09 апреля 2020

Похоже, Agora SDK автоматически деактивирует любые существующие AVAudioSessions, когда вы присоединяетесь к вызову, чтобы убедиться, что вы слышите собеседника. Я бы рекомендовал воспроизводить звук через API микширования звука Agora .

// Plays an audio effect file.
int soundId = 1; // The sound ID of the audio effect file to be played.
NSString *path = [[NSBundle mainBundle] pathForResource:@"ringing-sound-jalebi" ofType:@"mp3"]; // The file path of the audio effect file.
int loopCount = 1; // The number of playback loops. -1 means an infinite loop.
double pitch = 1; // Sets the pitch of the audio effect.
double pan = 1; // Sets the spatial position of the audio effect. 0 means the effect shows ahead.
double gain = 100; // Sets the volume. The value ranges between 0 and 100. 100 is the original volume.
BOOL publish = true; // Sets whether to publish the audio effect.
[self.agoraKit playEffect:soundId filePath:path loopCount:loopCount pitch:pitch pan:pan gain:gain publish:publish];
...