I want to play a youTube video using youtube video url.
I succeed in playing a video in iOS version 5.1.1 but the video does not played in iOS version 5.0.1 and 4.0 or below. I am using webview to play video.
I want to play a youTube video using youtube video url.
I succeed in playing a video in iOS version 5.1.1 but the video does not played in iOS version 5.0.1 and 4.0 or below. I am using webview to play video.
for IOS below 5 you need to use iframe :
NSString *youTubeVideoHTML = @"<iframe id=\"yt\" class=\"youtube-player\" type=\"text/html\" width=\"280\" height=\"186\" src=\"http://www.youtube.com/embed/xxxxxx\" frameborder=\"0\">";
and for ios 5 above we can use embed :
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"http://www.youtube.com/watch?v=xxxxxx?autoplay=1\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
Note: In IOS 6 i found out that url works only if we pass youtube url as : http://www.youtube.com/v/xxxxxx?autoplay=1
Hope this works out.
From your comment it looks like you are using the wrong embed code, youtube embeds now look like
<iframe width="560" height="315" src="http://www.youtube.com/embed/Cw2RzvK13F4" frameborder="0" allowfullscreen></iframe>
As mentioned before flash won't play on the iPhone, so it needs to use the HTML5 version, unfortunately I don't think 100% of youtube videos have been converted, but most should work.
You need to make sure your using the proper URL format for embedded videos. They changed it somewhat recently.
Youtube Embedded Players and Player Parameters - YouTube - Google Developers
It looks like this:
http://www.youtube.com/embed/VIDEO_ID
Here is my code which works well in all previous version of iOS 5.Just give a try with this code. I am sure this is going to fix your problem.
// Over here Just replace this url with your one's.
NSString *pdfString = @"http://www.youtube.com/watch?v=qe39vPFabuA";
NSString *htmlString = @"<html><head>\n"
"<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 320\"/></head>\n"
"<body style=\"background:FFF;margin-top:0px;margin-left:0px\">\n"
"<div><object width=\"320\" height=\"416\">\n"
"<param name=\"movie\" value=\"%@\"></param>\n"
"<param name=\"wmode\" value=\"transparent\"></param>\n"
"<embed src=\"%@\"\n"
"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"416\"></embed>\n"
"</object></div></body></html>\n";
[webView loadHTMLString:[NSString stringWithFormat:htmlString,[pdfString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]],[pdfString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] baseURL:nil];
Also, make sure to test the code in Device only. Testing on Simulator won't play the Video.