8

How to embed a Youtube video that has copyrighted content in it.

For example when you try playing this video(http://www.youtube.com/embed/ADBKdSCbmiM) in a UIWebView it says

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

How would I go about getting videos like this to play in an embedded player or a custom player that I would make using MPMoviePlayer or such. I know this is possible as following app does this. (http://itunes.apple.com/us/app/audioviz-view-your-songs-on/id547001249?mt=8)

Edit Few videos play in browser but in iOS Simulator its showing

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

Thanks for all the help!

iMeMyself
  • 1,649
  • 13
  • 28
Praxder
  • 2,315
  • 4
  • 32
  • 51
  • The restriction is based on a reverse lookup of the IP address you are using when accessing the video in question. Use a proxy from within the US and you will see that it suddenly plays without any problem. – Till Sep 14 '12 at 21:08
  • I dont think this this is correct as whenever you embed the full video normally it works fine its just when you try embeding the video that it denies you permission – Praxder Sep 14 '12 at 22:53
  • Ow, I think I missed the point. Well first of all this is true (that video is geo-restricted), but the point you aim for is another one. Sorry that I missed that. Your point is about embedding a YouTube video within a webpage and the limitations connected to that. – Till Sep 14 '12 at 22:59
  • Correct, Why wont it show you the video when its embeded and will when its not? Is there any code trick to get the embeded URL to work? – Praxder Sep 14 '12 at 23:01
  • The custom player you are mentioning most likely uses a rather well-known trick; fooling youtube into providing an MP4-version of that video, download it progressively and serve it back via a local http-server to MPMoviePlayerController. – Till Sep 14 '12 at 23:07
  • And how would I go about doing that? – Praxder Sep 15 '12 at 00:54
  • 1
    @Shredder2794 have you find solution to your problem? i have come across similar issue, so if you have found solution please share it – iMeMyself Oct 08 '12 at 09:09
  • i came across a google group discussion stating The reason for the peculiar error message is because in code one have linked directly to the Flash object, which is supposed to be embedded somewhere, but its haven't embedded yet, so that's confusing YouTube. It's not being restricted from "playback on youtube.com". there seems to be alternate link to youtube .. the reason seems viable but im wondering on how to correct this – iMeMyself Oct 08 '12 at 09:22

3 Answers3

8

You can use player vars while initializing youtube sdk:

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

Enjoy!

atulkhatri
  • 10,896
  • 3
  • 53
  • 89
3

To play the youtube video using uiwebview:

  1. First check if your youtube URL is played or not in browser. If the video doesn't play in the browser it won't play in the device either

  2. You only check in the device; the video doesn't play in simulator

    - (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]; 
    
    }
    
lc.
  • 113,939
  • 20
  • 158
  • 187
iCrazyDev
  • 925
  • 5
  • 16
  • all my you tube urls plays in browser (also in mobile browser) but not from app.. and i have been through http://www.developerfeed.com/ios/topic/how-embed-youtube-video-uiview-iphone link .. my prob is most of the you tube videos work well but some gives **This video contains content from SME . It is restricted from playback on certain site** issue – iMeMyself Oct 08 '12 at 13:39
  • this method does not work anymore on ios-6, as you have to use embed method to play video...and i am also facing the same problem using new method to play youtube video – Bhupendra Oct 11 '12 at 11:12
  • As of iOS 6 you cannot use this method to embed YouTube videos in the UIWebView. You must use iframe, check this answer: http://stackoverflow.com/a/12860616/662605 – Daniel Oct 13 '12 at 13:36
  • @Daniel and Bhupendra yeah.. we should use iFrames on ios6 as in here http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html – iMeMyself Oct 14 '12 at 09:42
2

If you're embedding on a mobile app, you need to set your Referer in your request header for the video. Otherwise, Youtube automatically blacklists you if your Referer field is left blank.

I answered this in detail here. I was experiencing this myself and I fixed it in my case (iOS app using React Native). I can play Vevo, WMG, and all other restricted content now.

Community
  • 1
  • 1
Jake
  • 990
  • 1
  • 10
  • 17