I am working on one app where I am giving functionality to user to play Youtube video saved in database. And if user wants, he can update the video.
Say I have saved a link like http://www.youtube.com/watch?v=1Ziku4FLka4 in DB and I am playing the same link on a button click for which I have implemented code like below :
UIWebView *wv;
strUTube = @"http://www.youtube.com/watch?v=1Ziku4FLka4";
wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,10,viewBG.frame.size.width,viewBG.frame.size.height)];
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: brown;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendFormat:@"<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\"", strUTube];
[html appendFormat:@"width=\"%0.0f\" height=\"%0.0f\"></embed>", viewBG.frame.size.width,viewBG.frame.size.height];
[html appendString:@"</body></html>"];
NSLog(@"html:%@",html);
[wv loadHTMLString:html baseURL:nil];
[viewBG addSubview:wv];
[self.view addSubview:viewBG];
Then on another button click, I am calling home page of Youtube and fetching the URL opened on a button click event with following code :
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
NSLog(@"currentURL2 : %@",currentURL);
But the URL results into result like http://m.youtube.com/watch?feature=m-trends&v=to7uIG8KYhg which cannot be played later on.
I also tried to open the URL on my Mac Book but in vain.
Simple trick extract videoID from below currentURL:
Now create new Youtube VideoURL like
Now play this newVideoURL in embedded player.
http://www.youtube.com/watch?v=to7uIG8KYhg