8

如何嵌入包含受版权保护内容的 Youtube 视频。

例如,当您尝试播放此视频(http://www.youtube.com/embed/ADBKdSCbmiM)时,UIWebView它会显示

 This Video Contains content from Vevo. It is restricted from playback on certain sites

我将如何让这样的视频在嵌入式播放器或我将使用的自定义播放器中播放MPMoviePlayer。我知道这是可能的,因为以下应用程序会这样做。(http://itunes.apple.com/us/app/audioviz-view-your-songs-on/id547001249?mt=8

编辑 很少有视频在浏览器中播放,但在 iOS 模拟器中显示

This video contains content from SME . It is restricted from playback on certain site

感谢所有的帮助!

4

3 回答 3

8

您可以player vars在初始化 youtube sdk 时使用:

NSDictionary *playerVars = @{
                             @"origin" : @"http://www.youtube.com",
                             };
[self.playerView loadWithVideoId:@"KOvoD1upTxM" playerVars:playerVars];

享受!

于 2016-04-03T10:37:21.017 回答
3

要使用以下方式播放 youtube 视频uiwebview

  1. 首先检查您的 youtube URL 是否在浏览器中播放。如果视频没有在浏览器中播放,它也不会在设备中播放

  2. 您只签入设备;视频无法在模拟器中播放

    - (void) displayGoogleVideo
    
        {
    
        CGRect rect = [[UIScreen mainScreen] bounds];
    
        CGSize screenSize = rect.size;
    
        UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
    
        webView.autoresizesSubviews = YES;
    
        webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
    
        NSString *videoUrl = @"http://www.youtube.com/v/oHg5SJYRHA0"; // valid youtube url
    
    
        NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"320\" height=\"480\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"480\"></embed></object></div></body></html>",videoUrl,videoUrl]    ;
    
    
    
        [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
    
    
        [window addSubview:webView];
    
        [webView release]; 
    
    }
    
于 2012-10-08T13:31:52.257 回答
2

如果您要嵌入移动应用程序,则需要在视频的请求标头中设置您的。Referer否则,如果您的推荐人字段留空,Youtube 会自动将您列入黑名单。

我在这里详细回答了这个问题。我自己也遇到过这个问题,并在我的情况下修复了它(使用 React Native 的 iOS 应用程序)。我现在可以玩 Vevo、WMG 和所有其他受限内容。

于 2016-09-22T22:59:37.590 回答