Embed Youtube videos :- with contains content from * , it is restricted from playback on certain site

16,161

Solution 1

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]; 
    
    }
    

Solution 2

You can use player vars while initializing youtube sdk:

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

Enjoy!

Solution 3

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.

Share:
16,161

Related videos on Youtube

Shredder2794
Author by

Shredder2794

Updated on June 17, 2022

Comments

  • Shredder2794
    Shredder2794 almost 2 years

    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
      iMeMyself over 11 years
      @Shredder2794 have you find solution to your problem? i have come across similar issue, so if you have found solution please share it
  • iMeMyself
    iMeMyself over 11 years
    all my you tube urls plays in browser (also in mobile browser) but not from app.. and i have been through developerfeed.com/ios/topic/… 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
  • Bhupendra
    Bhupendra over 11 years
    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
  • Daniel
    Daniel over 11 years
    As of iOS 6 you cannot use this method to embed YouTube videos in the UIWebView. You must use iframe, check this answer: stackoverflow.com/a/12860616/662605
  • iMeMyself
    iMeMyself over 11 years
    @Daniel and Bhupendra yeah.. we should use iFrames on ios6 as in here apiblog.youtube.com/2010/07/…