title: How to autoplay youtube video (without user interaction) in iOS swift
body: <p>I am trying to autoplay video of youtube using YTplayer and load the Youtube video using VideoID,
  I had also tried using loadHTMLString in Webview.
  is iOS not allow to autoplay youtube ?</p>
  
  <p>here is my code: 1) using YTplayer</p>
  
  <pre><code>let fullNameArr = video_url!.componentsSeparatedByString("=")
  let video: String = fullNameArr[1]
  enYTplayer.webView?.mediaPlaybackRequiresUserAction = false
   YTplayer.webView?.allowsInlineMediaPlayback = true
   YTplayer.loadWithVideoId(video)  
   YTplayer.playVideo()
  </code></pre>
  
  <p>2)using webView (iframe)</p>
  
  <pre><code>let vidurl = "https://www.youtube.com/embed/LG-_Dz6nseQ"
  yutub_webview.loadHTMLString("&lt;iframe width=\"\(yutub_webview.frame.size.width)\" hight=\"\(yutub_webview.frame.size.height)\" src=\"\(vidurl)?playsinline=1\" frameborder=\"0\" allowfullscreen &amp; autoplay=1 &amp;showinfo=0 &amp;controls=0 autohide=1&gt;&lt;/iframe&gt;", baseURL: nil)
  </code></pre>
  
  <p>3) using HTML</p>
  
  <pre><code>let youTubeVideoHTML :NSString = "&lt;html&gt;&lt;head&gt;&lt;style&gt;body{margin:0px 0px 0px 0px;}&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:'200', height:'204', videoId:'8LVN7WVgx0c', events: { 'onReady': onPlayerReady } }); } function onPlayerReady(event) { event.target.playVideo(); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;";
      yutub_webview.loadHTMLString(youTubeVideoHTML as String,baseURL:nil)
  </code></pre>
  
  <p>and also tried out this one:</p>
  
  <pre><code>yutub_webview.loadHTMLString("&lt;html&gt;&lt;body style='margin:0px;padding:0px;'&gt;&lt;script type='text/javascript' src='http://www.youtube.com/iframe_api'&gt;&lt;/script&gt;&lt;script type='text/javascript'&gt;function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){a.target.playVideo();}&lt;/script&gt;&lt;iframe id='playerId' type='text/html' width='300' height='200' src='http://www.youtube.com/embed/LG-_Dz6nseQ? enablejsapi=1&amp;rel=0&amp;playsinline=1&amp;autoplay=1' frameborder='0'&gt;&lt;/body&gt;&lt;/html&gt;",baseURL: NSBundle.mainBundle().bundleURL)
  </code></pre>
  
  <p>but still default play button is there and video not autoplay. 
  can any one tell me what i am doing wrong with these?</p>