1
votes

I understand that based on AVAudioSession category AVPlayer will pause background audio currently played by other app when starting its playback. I wonder if this is the expected behavior regardless of the type item/content being played?

I'm asking as in my case showing video with no sound. The video files contain no audio track. AVPlayer itself is also set to muted. It just a little weird to me that I still have to change to AVAudioSession category even though I do not produce audio. So I want to know if that is by design or if there is something that I miss. For example, could I set up AVPlayer with no audio session so that it knows not to worry about audio or something like that.

1

1 Answers

2
votes

No. Just set the audio category to "Ambient" so that it doesn't step on any other audio:

AVAudioSession *session = [AVAudioSession sharedInstance];
if (session) {
    NSError *setCategoryError = nil;
    BOOL success = [session setCategory:AVAudioSessionCategoryAmbient error:&setCategoryError];
    if (success) {
        NSError *activationError = nil;
        [session setActive:YES error:&activationError];
    } else {
        NSLog(@"Failed to set music category to ambient. May interrupt other audio.");
    }
}