Spalooda
Spalooda

Reputation: 113

How to play a youtube video on iphone, not in fullscreen

I'd like to play a YouTube video in my iPhone app inside a view or a webview. I know it's possible to play inline videos on the iPad, but I haven't been able to do that on the iPhone. As soon as the video starts playing, the movie player goes to fullscreen so my UI is not visible.

Does anyone know how to overcome this limitation? Is there any other app that does that on the app store?

Thanks!

Upvotes: 4

Views: 1825

Answers (1)

Midhun MP
Midhun MP

Reputation: 107121

Use this code for adding the you tube into your application.

For this you need to setup a webview in your view. Then call the loadHTMLString:baseURL: method on the UIWebView instance with some carefully constructed HTML that contains the YouTube embedded player code snippet and some supporting HTML to make sure that the video thumbnail appears correctly. Set the base URL to the URL of your website (it doesn't do anything here -- ordinarily UIWebView uses it to handle relative URL links correctly).

NSString *youTube = @"<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=\"212\" height=\"172\">
<param name=\"movie\" value=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"
type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"172\"></embed>
</object></div></body></html>";

[webView loadHTMLString:youTube baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];

For further reference : YouTube

Upvotes: 1

Related Questions