1

I have video embedded in my application using this solution (html string in UIWebView): http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

Unfortunately client requires his own thumbnail. I would like to solve it by creating UIWebView once he taps on this thumbnail and play the video inside automatically.

How can I do it?

Engeor
  • 328
  • 4
  • 14
  • Ok, I don't like this kind of solution and I honestly want something like iApple posted works but I found this and it works: http://boydlee.com/ios-iphone-ipad/autoplay-youtube-video-inside-webuiview.html What is same as here (finally find it via google): http://stackoverflow.com/questions/5510429/how-can-i-start-a-youtube-video-without-the-user-touching-the-uiwebview-itself – Engeor Mar 01 '12 at 10:35
  • Check out [Detecting UIWebView finish to play youtube video on iPad](http://stackoverflow.com/questions/9459711/detecting-uiwebview-finish-to-play-youtube-video-on-ipad/14702453#14702453) for a solution – Ilias Karim Feb 05 '13 at 07:47

2 Answers2

0

Try this:-

NSString *htmlString = [NSString stringWithFormat:@"<html><head>"
                        "<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 50\"/></head>"
                        "<body style=\"background:#F00;margin-top:0px;margin-left:0px\">"
                        "<div><object width=\"50\" height=\"50\">"
                        "<param name=\"movie\" value=\"%@\"></param>"
                        "<param name=\"wmode\" value=\"transparent\"></param>"
                        "<embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"50\" height=\"50\"></embed>"
                        "</object></div></body></html>",[d objectForKey:@"hrefUrl"],[d objectForKey:@"hrefUrl"]];

[videoView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];
Deepesh
  • 8,065
  • 3
  • 28
  • 45
  • 1
    It doesn't work for what I need. It shows thumbnail and then I must tap the video to make it play. – Engeor Mar 01 '12 at 11:59
-2

Following is the html string to play video automatically inside UIWebView...

NSString *embedHTML = [NSString stringWithFormat:@"<html><body><video controls=\"controls\" autoplay=\"autoplay\"><source src=\"%@\" type=\"video/mp4\"/></video></body></html>", url];
[_webView loadHTMLString:embedHTML baseURL:baseURL];

I have tried the following one, it is working fine and also starts to play automatically.

NSString *embedHTML = @"<html><body bgcolor="black"><embed id="yt" src="http://www.youtube.com/watch?v=9vyYHVB-QnY"type="application/x-shockwave-flash" width="320.00" height="370.00"></embed></body></html>";
[_webView loadHTMLString:embedHTML baseURL:baseURL]; 
alloc_iNit
  • 5,173
  • 2
  • 26
  • 54
  • I am sorry, this doesn't works. It even didn't show the video. – Engeor Mar 01 '12 at 10:19
  • > Still can't get it works. I am using url in this form: http://www.youtube.com/watch?v=9vyYHVB-QnY and baseURL nil. Is it ok? – Engeor Mar 01 '12 at 11:02
  • I am sorry but it still doesn't play the video, showing just black rectangle. – Engeor Mar 01 '12 at 11:58
  • Well, as it is a youtube video url, you might not be able to view on simulator. As I have check this code and its working good with iPhone 4. – alloc_iNit Mar 01 '12 at 12:31