16

I have looked everywhere on how to do this and haven't found an answer yet. Is it possible to play a youtube video in a UIWebView on an iPhone inline, i.e. not fullscreen? I know that the iPhone doesn't support flash, but youtube supports html5 and has h.264 videos doesn't it? shouldn't I be able to do this then?

I have set allowsInlineMediaPlayback to YES, but still it plays fullscreen.

Oded
  • 2,239
  • 2
  • 18
  • 16

3 Answers3

34

Yes you can, you need to set property on UIWebView

 webView.allowsInlineMediaPlayback=YES;

And you need to add &playsinline=1 to YouTube iframe embedding code.

 <iframe webkit-playsinline width="200" height="200" src="https://www.youtube.com/embed/GOiIxqcbzyM?feature=player_detailpage&playsinline=1" frameborder="0"></iframe>

Tested on iPhone 4S running iOS 6.1.2 works like a charm.

timing
  • 6,340
  • 1
  • 17
  • 16
stringCode
  • 2,274
  • 1
  • 23
  • 32
  • This is correct-- with these two settings in place inline playback will work on iPhone. – Marc Charbonneau Mar 21 '13 at 23:39
  • can you please show the code with iFrame api of youtube? As i want to run the video from a certain time – z22 Jul 23 '13 at 11:01
  • Not sure what do you mean ? second line in the html (iFrame api). – stringCode Jul 24 '13 at 10:52
  • If I understand correctly this requires an 'app' (i.e. access to UIWebView, which seems to be a browser type object) -- i.e. its not something I can leverage within a normal webpage. Is that correct? Is there a way to force iOS to play inline? (i.e. I have a video and want people to click a button when they see certain queues... a no-go if the vid plays full screen)... – Ben A. Hilleli Aug 21 '14 at 19:58
  • Unfortunately your assumption is correct. This does not work in iPhone's Safari. You need to create you own app in witch you use UIWebView class. However it will work on iPad's Safari. You might be able to get it working on iPhone as well with custom html 5 player, but I never tried that. See http://stackoverflow.com/questions/5438520/html5-video-player-behavior-on-iphone-and-ipod-in-safari-web-apps – stringCode Aug 24 '14 at 13:12
  • awesome solution +1...is it possible to play youtube video within its area, i dont want play in full screen. – Bandish Dave Jan 07 '15 at 10:38
  • Easiest Solution +1..Thanks – Kundan Feb 05 '15 at 08:23
  • Does this work for ios8? I still got the video played full-screen. – Demonedge Oct 25 '15 at 05:16
  • I have a strange issue on iOS 9, it sometimes works, but mor often not – Frane Poljak Feb 09 '16 at 15:04
3

allowsInlineMediaPlayback UIWebView properties

Boolean value that determines whether HTML5 videos play inline or use the native full-screen controller. (developer.apple.com)

You can use this feature on iPad. On the iPhone there is no such function. If you try play video with uiwebview on iPhone it will be played in full screen mode.

Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
0

Yes, you can play any embed video inline UIWebView itself with help of "playsinline=1".

Source code like:

    NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1] ;
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendString:@"<iframe webkit-playsinline width=\"300\" height=\"220\" src=\"http://www.ustream.tv/embed/23192315?html5ui&showtitle=false&playsinline=1\" frameborder=\"0\"></iframe>"];
[html appendString:@"</body></html>"];
[self.webViewRef loadHTMLString:html baseURL:nil];
Mannam Brahmam
  • 2,225
  • 2
  • 24
  • 36