Agora-Flutter-SDK icon indicating copy to clipboard operation
Agora-Flutter-SDK copied to clipboard

[iOS] Local and remote audio disappears for seconds.

Open AndriiVivcharenko opened this issue 3 years ago • 8 comments

Context: I have a group call functionality with additional improvements. Basically, it shows a short looping video locally for each user, and the video changes frequently, average each 30-40 seconds.

Issue: Whenever it starts showing the video agora audio disappears for seconds and then starts playing again. The issue happens only when initializing video controller ~~the initialized video controller renders on the screen (Not during controller initialization)~~. Once audio disappears following message is printed in the console output:

[avas] AVAudioSession_iOS.mm:1271 Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

Also if I joined using a headset, before the audio disappears I'm able to hear an audio indication that the call was ended.

I also play some audio files using audio mixing locally for each user. These audio files play with no issues.

Smartphone: Device: iPhone 8 plus OS: iOS 15.5 Agora SDK: 5.2.0

AndriiVivcharenko avatar Jun 27 '22 16:06 AndriiVivcharenko

Maybe you can try set setParameters("{\"che.audio.keep.audiosession\": true}") to stop the Agora SDK from ending the audio session, but you should control the audio session yourself in this way.

littleGnAl avatar Jun 30 '22 13:06 littleGnAl

Hey

It didn’t fix. I made a mistake in the issue description, it happens when "initialize" method is executed on a video controller. I also download the video file before initialization, but the same thing happens if I use the network video controller through the URL.

That’s the updated output when it kills audio session:

[warning] /tmp/jenkins/IRIS-SDK/rtc/cxx/src/internal/rtc_engine_event_handler.cc:43 onWarning warn 1029 msg nullptr
capture: isfull
[avas]   AVAudioSession_iOS.mm:1271 Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.
[debug] /tmp/jenkins/IRIS-SDK/rtc/cxx/src/iris_rtc_engine.cc:104 CallApi api_type 50 params {"volume":0}
[debug] /tmp/jenkins/IRIS-SDK/rtc/cxx/src/iris_rtc_engine.cc:114 CallApi ret 0 result 

AndriiVivcharenko avatar Jul 01 '22 10:07 AndriiVivcharenko

@AndriiVivcharenko how do you play your video?

plutoless avatar Jul 01 '22 11:07 plutoless

and when did you call this api? did you call it before you join channel? setParameters("{\"che.audio.keep.audiosession\": true}") my guess is your player is somehow trying to modify audiosession which violates our settings, our sdk will try to recover this when it happens, and the audio lost should be caused by this. The api above means sdk release the audio session control to you so it should at least stop the warning. maybe you can help provide some more info?

plutoless avatar Jul 01 '22 11:07 plutoless

I play it using video_player plugin 2.4.5

my video initialization code:

// video downloading here

videoPlayer = VideoPlayerController.file(
    file,
    videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true));

videoFuture = videoPlayer!.initialize().then((value) async {
  videoPlayer!.setVolume(0);
  videoPlayer!.setLooping(true);
  if (isPlaying && playOnInit) {
    videoPlayer!.play();
  }
});

I forgot to add await setParameters in async execution. Call it right after creating RtcEngine instance, before joining channel

The AVAudioSession_iOS is gone, but the same thing happens with audio and still getting 1029 warning.

AndriiVivcharenko avatar Jul 01 '22 12:07 AndriiVivcharenko

Seems like if I don’t use mixWithOthers option it works fine.

then 1029 warning makes sense.

https://developer.apple.com/documentation/avfaudio/avaudiosessioncategoryoptions/avaudiosessioncategoryoptionmixwithothers

AndriiVivcharenko avatar Jul 01 '22 12:07 AndriiVivcharenko

@AndriiVivcharenko so it works now if you set mixWithOthers to false?

plutoless avatar Jul 01 '22 12:07 plutoless

It does.

But I was wrong, the warning says the opposite thing.

It sets category in controller init to AVAudioSessionCategoryPlayback 1029 says it should always be AVAudioSessionCategoryPlayAndRecord

I have no idea why this is related. https://github.com/flutter/plugins/blob/b5e4ad208a0651cd19e5162619a3f958ddf18cff/packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m#L629

AndriiVivcharenko avatar Jul 01 '22 13:07 AndriiVivcharenko

Here's the solution I found. I just added checks to make sure that AVAudioSession is not changed when using video_player with agora. It might work for other plugins that change AVAudioSession.

- (void)initialize:(FLTInitializeMessage *)input
                   error:(FlutterError *_Nullable __autoreleasing *)error {
  // Added this condition.
  if(input.controlAVAudioSesson.boolValue) {
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  }

  [self.playersByTextureId
      enumerateKeysAndObjectsUsingBlock:^(NSNumber *textureId, FLTVideoPlayer *player, BOOL *stop) {
        [self.registry unregisterTexture:textureId.unsignedIntegerValue];
        [player dispose];
      }];
  [self.playersByTextureId removeAllObjects];
}
- (void)setMixWithOthers:(FLTMixWithOthersMessage *)input
                   error:(FlutterError *_Nullable __autoreleasing *)error {
                    
  // Same for setMixWithOthers              
  if (input.mixWithOthers.boolValue && input.controlAVAudioSesson.boolValue) {
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
                                     withOptions:AVAudioSessionCategoryOptionMixWithOthers
                                           error:nil];
  } else if(input.controlAVAudioSesson.boolValue) {
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  }
}

AndriiVivcharenko avatar Feb 17 '23 09:02 AndriiVivcharenko

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please raise a new issue.

github-actions[bot] avatar Apr 28 '23 08:04 github-actions[bot]