如何嵌入包含受版权保护内容的Youtube视频。
例如,当您尝试在UIWebView
中播放此视频(http://www.youtube.com/embed/ADBKdSCbmiM)时,它说
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
感谢所有的帮助!
初始化 youtube SDK 时使用player vars
:
NSDictionary *playerVars = @{
@"origin" : @"http://www.youtube.com",
};
[self.playerView loadWithVideoId:@"KOvoD1upTxM" playerVars:playerVars];
享受!
要使用uiwebview
播放YouTube视频:
-
首先检查您的YouTube网址是否在浏览器中播放。如果视频无法在浏览器中播放,则也无法在设备中播放
-
您只签入设备;视频不会在模拟器中播放
- (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]; }
如果您要嵌入移动应用,则需要在视频的请求标头中设置Referer
。否则,如果您的"引用者"字段留空,Youtube 会自动将您列入黑名单。
我在这里详细回答了这个问题。我自己也经历过这个问题,我在我的情况下修复了它(使用 React Native 的 iOS 应用程序)。我现在可以玩Vevo,WMG和所有其他受限制的内容。