无法在 iOS 上使用 YTPlayerView 在后台播放 YouTube 视频

Not able to play youtube videos in background on iOS, using YTPlayerView

在我的 iOS 应用中,我正在使用 YTPlayerView 播放 YouTube 视频(有关信息,请参阅 this link),但是视频如果应用进入后台,播放暂停。我想继续在后台播放视频,我将 "Audio and AirPlay" 添加到 "Required background modes" 并以这种方式在应用程序委托中设置音频会话:

- (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]);
    }
}

但是当应用程序进入后台时视频会暂停。我还应该做些什么才能让它发挥作用?

经过多次调查,我发现这是不可能的。以下关于此问题的评论解释了原因:

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.