3
votes

In my iOS app, I'm playing youtube videos using YTPlayerView (see this link for information), but video playback pauses if app has entered background. I would like to continue playing videos in background, I added "Audio and AirPlay" to "Required background modes" and set audio session in application delegate this way:

- (void) setAudioSession
{
    NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryErr];
    if (setCategoryErr)
    {
        NSLog(@"Setting Audio Session Category Error: %@",[setCategoryErr description]);
    }
    [audioSession setActive:YES error:&activationErr];
    if (activationErr)
    {
        NSLog(@"Activating Audio Session Error: %@",[activationErr description]);
    }
}

but however video pauses when app enters background. What else should I do to make it work?

1
Hello Radu, did you ever figure this out? Please update us if you found a solution.sudoExclaimationExclaimation
Radu, can you please update?Roi Mulia
@RoiMulia Still no solution found (iOS Dev

1 Answers

0
votes

After many investigations, I've found that it's not possible. The following comment on this issue explains why:

Technically speaking YouTube is a VIDEO streaming service so naturally the video must be visible in order to also hear the audio. Therefore, entering background mode should also stop the video playback.

In order to comply with YouTube TOS and Apple guidelines you need to display the video - and stop it from playing when locking the screen. Sadly, no background playback of YouTube videos.