title: Fetch and Play back YouTube URL in Objective C
body: <p>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.</p>
  
  <p>Say I have saved a link like <a href="http://www.youtube.com/watch?v=1Ziku4FLka4" rel="nofollow noreferrer">http://www.youtube.com/watch?v=1Ziku4FLka4</a> in DB and I am playing the same link on a button click for which I have implemented code like below : </p>
  
  <pre><code>   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:@"&lt;html&gt;&lt;head&gt;"];
      [html appendString:@"&lt;style type=\"text/css\"&gt;"];
      [html appendString:@"body {"];
      [html appendString:@"background-color: transparent;"];
      [html appendString:@"color: brown;"];
      [html appendString:@"}"];
      [html appendString:@"&lt;/style&gt;"];
      [html appendString:@"&lt;/head&gt;&lt;body style=\"margin:0\"&gt;"];
      [html appendFormat:@"&lt;embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\"", strUTube];
  
      [html appendFormat:@"width=\"%0.0f\" height=\"%0.0f\"&gt;&lt;/embed&gt;", viewBG.frame.size.width,viewBG.frame.size.height];
      [html appendString:@"&lt;/body&gt;&lt;/html&gt;"];
  
      NSLog(@"html:%@",html);
      [wv loadHTMLString:html baseURL:nil];
      [viewBG addSubview:wv];
  
      [self.view addSubview:viewBG];
  </code></pre>
  
  <p>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 :</p>
  
  <pre><code>NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
  NSLog(@"currentURL2 : %@",currentURL);
  </code></pre>
  
  <p>But the URL results into result like <a href="http://m.youtube.com/watch?feature=m-trends&amp;v=to7uIG8KYhg" rel="nofollow noreferrer">http://m.youtube.com/watch?feature=m-trends&amp;v=to7uIG8KYhg</a> which cannot be played later on.</p>
  
  <p>I also tried to open the URL on my Mac Book but in vain.</p>