gpt4 book ai didi

ios - 无法使用 YTPlayerView 在 iOS 后台播放 youtube 视频

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:35:16 25 4
gpt4 key购买 nike

在我的 iOS 应用中,我正在使用 YTPlayerView 播放 youtube 视频(有关信息,请参阅 this 链接),但如果应用进入后台,视频播放会暂停。我想继续在后台播放视频,我将“音频和 AirPlay”添加到“必需的后台模式”,并以这种方式在应用程序委托(delegate)中设置 Audio Session :

- (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.

关于ios - 无法使用 YTPlayerView 在 iOS 后台播放 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31855860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com