Can't play YouTube videos in background on iOS using YTPlayerView

In my iOS app, I play youtube video using YTPlayerView (see this link for info), but video playback pauses if the app has entered a background. I would like to continue playing the video in the background, I added "Audio and AirPlay" to "Required Backgrounds" and set the audio session in the delegate's deletion like this:

- (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, the video is paused when the app goes into the background. What else do I have to do to make it work?

+3


source to share


1 answer


After a lot of research, I've found that this is not possible. The following comment on the subject explains why:



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

To comply with YouTube TOS and Apple's rules, you'll need to display the video - and stop it from playing when you lock the screen. Unfortunately, there is no background video playback on YouTube.

0


source







All Articles