如何在视频完成后使YouTube视频退出全屏

时间:2014-07-01 20:30:43

标签: ios youtube-api

我正在使用Youtube iOS API帮助程序来显示视频。大多数用户都希望全屏观看视频,但观看视频后,应用需要退出全屏视频,以便用户完成相关任务。有没有办法在videoEnded上退出视频。

2 个答案:

答案 0 :(得分:0)

playerVars 字典中,您应设置属性@"autohide" : @1 这将使视频在视频完成后全屏退出。 它看起来像这样:

NSDictionary *playerVars = @{@"autohide" : @1};
[self.playerView loadWithVideoId:self.videoID playerVars:playerVars];

答案 1 :(得分:0)

这对我有用, 来源https://gist.github.com/akisute/a46c5ec54d27f73b62da

- (void)exitFullScreenVideo:(BOOL)animated completion:(void (^)(void))completion
    {
        if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0) {
            BOOL isFullScreenVideoContent = NO;
            for (UIWindow *window in [UIApplication sharedApplication].windows) {
                if ([window.rootViewController.presentedViewController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
                    [window.rootViewController dismissViewControllerAnimated:animated completion:^{
                        window.rootViewController = nil;
                        window.hidden = YES;
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
                        [window performSelector:NSSelectorFromString(@"release")];
    #pragma clang diagnostic pop
                        completion();
                    }];
                    isFullScreenVideoContent = YES;
                    break;
                }
            }
            if (!isFullScreenVideoContent) {
                completion();
            }
        } else {
            completion();
        }
    }