3

I have the URL for example https://www.youtube.com/watch?v=c2ccXwwmcnA. If I pass this URL to UIWebView it automatically the play the Video. I have the tried the following ways

Option-1

@property (weak, nonatomic) IBOutlet UIWebView *webvie; 


  NSString *url=@"https://www.youtube.com/watch?v=7jYa7dfrXKU";

  self.webvie.allowsInlineMediaPlayback = YES;
 self.webvie.scrollView.bounces = NO;
self.webvie.mediaPlaybackRequiresUserAction = NO;

[self.webvie loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];

Option-2

NSString *youTubeHTMLTemplate = @"<html><head><style type=\"text/css\">body { background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed></body></html>"; 
finalHtml = [NSString stringWithFormat:youTubeHTMLTemplate, fullYopuTubeUrl, htmlFrameWidth, htmlFrameHeight];

Option-3

How to autoplay a YouTube video in a UIWebView

I dont want auto play the in UIWebview play youtube video

but all options does not helped me,

Community
  • 1
  • 1
Shangari C
  • 792
  • 1
  • 5
  • 17
  • 1
    I think you have to add an `autoplay` attribute inside the `embed` tag. – Kyle Emmanuel Dec 23 '15 at 05:16
  • Do you want to auto play the video or not auto play the video? Also, have you looked into using [YouTube`s Helper Library for iOS](https://developers.google.com/youtube/v3/guides/ios_youtube_helper)? – Daniel Storm Dec 23 '15 at 05:17
  • Already we tried with this, the link we attached the ID for play the video , but my requirment is load the URL first after that I need the video want to play on automatically. – Shangari C Dec 23 '15 at 05:25
  • @KyleEmmanuel -- Wait I try once – Shangari C Dec 23 '15 at 05:26
  • @ShangariC: just wondering how you're able to autoplay in UIWebView when Apple prohibits autoplay because it hogs user data? – Pangu Feb 23 '16 at 21:01

1 Answers1

10

Thanks @Kyle, I tried your comment , I added the &autoplay=1 in after the URL it working perfectly. The answer is

NSString *url=@"https://www.youtube.com/watch?v=7jYa7dfrXKU&autoplay=1";


[self.webvie loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
self.webvie.scrollView.bounces = NO;
[self.webvie setMediaPlaybackRequiresUserAction:NO]; 
Shangari C
  • 792
  • 1
  • 5
  • 17