title: How to play youtube/vimeo video within the application in iPhone
body: <p>I am building an application where I want to play video from url like Youtube, Vimeo, Direct url. I am making custom player using AVPlayer to play a video from a direct url of video clip(like www.abc/play.mp4). But later I faced a huge issue to play youtube &amp; vimeo video. And after searching a lot I found these link where it says without using UIWebview I can't play a Youtube link:</p>
  
  <p><a href="https://stackoverflow.com/questions/1779511/play-youtube-videos-with-mpmovieplayercontroller-instead-of-uiwebview/1781192#1781192">Play YouTube videos with MPMoviePlayerController instead of UIWebView</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18287889/playing-video-from-youtube-link-without-uiwebview/18288018#18288018">Playing video from youtube link without UIWebView</a> </p>
  
  <p>So I just used this code:</p>
  
  <pre><code>NSString *youTubeVideoHTML = @"&lt;html&gt;&lt;head&gt;&lt;style&gt;body{margin:0;}&lt;/style&gt;&lt;/head&gt; &lt;body&gt; &lt;div id=\"player\"&gt;&lt;/div&gt; &lt;script&gt; var tag = document.createElement('script'); tag.src = 'http://www.youtube.com/player_api'; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:\'100%%\', height:'200px', videoId:\'%@\', events: { 'onReady': onPlayerReady } }); } function onPlayerReady(event) { event.target.playVideo(); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;";
  
  NSString *html = [NSString stringWithFormat:youTubeVideoHTML, videoId];
  self.embedded_player_view.mediaPlaybackRequiresUserAction = NO;
  
  [self.embedded_player_view loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
  </code></pre>
  
  <p><strong><em>Now when I click on youtube/Vimeo video link from tableview its playing the video with the default player i.e. quicktime player. Its not running the video within the UIWebview frame itself.
  But I want to show the video in the 1st half of the screen i.e my UIWebview frame. Is that possible?</em></strong></p>
  
  <p>In my app I can see this:</p>
  
  <h2><strong>when clicking on red play button I can see the video in full screen in quicktime player like this:</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/geoEv.png" alt="enter image description here">   <img src="https://i.stack.imgur.com/mA13v.png" alt="enter image description here"></p>
  
  <h2><strong>But I want to show the video within the same webView frame not via quick time player. It should play like this:</strong></h2>
  
  <p><img src="https://i.stack.imgur.com/2xvqf.png" alt="enter image description here"></p>
  
  <p>Same does in <a href="https://itunes.apple.com/in/app/musictube-free-free-music/id632522670?mt=8" rel="nofollow noreferrer">MusicTube</a> and <a href="https://itunes.apple.com/us/app/playtube-free-videos-from/id661624671?mt=8" rel="nofollow noreferrer">PlayTube</a>.</p>
  
  <p>Or is there any other way to achieve the same? Any help will be appreciated. Thanks in advance.</p>