Note that there are some explanatory texts on larger screens.

plurals
  1. POYouTube video not closing after it finishes playing
    primarykey
    data
    text
    <p>I'm currently loading a YouTube video inside a <code>-UIwebView</code>, this is working perfectly and the video starts playing automatically. but the problem is that once the video finishes inside the <code>-UIwebView</code>it just stops and shows the play button. I would however want the video player to close so the users wouldn't have to manually hit the "Done" button every time.</p> <p><a href="http://gyazo.com/cfab487270f6cec6f9176000a6aa5a20.png" rel="nofollow">Image of the screen when the video doesn't close.</a></p> <p>Here's the link I launch the video inside the <code>-UIwebview</code></p> <pre><code>NSString *youTubeVideoHTML = [NSString stringWithFormat:@"&lt;!DOCTYPE html&gt;&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:'320', height:'200', videoId:'%@', events: { 'onReady': onPlayerReady, } }); } function onPlayerReady(event) { event.target.playVideo(); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;", [[NSUserDefaults standardUserDefaults] objectForKey:@"detailVideoURL"]]; </code></pre> <p><strong>EDIT:</strong></p> <p>I tried implementing the first answer into my code and this is how it ended up like. I'm still unsure what I should add into the callback ?</p> <pre><code>NSString *youTubeVideoHTML = [NSString stringWithFormat:@"&lt;!DOCTYPE html&gt;&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:'320', height:'200', videoId:'%@', events: { 'onReady': onPlayerReady, } }); } function onPlayerReady(event) { event.target.playVideo(); } function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING &amp;&amp; !done) { setTimeout(stopVideo, 6000); done = true; } if (event.data == YT.PlayerState.ENDED) { window.location = "callback:nil"; }; } function stopVideo() { player.stopVideo(); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;", [[NSUserDefaults standardUserDefaults] objectForKey:@"detailVideoURL"]; </code></pre> <p>Image of the error : <a href="http://gyazo.com/31da955d8af98f40b82789a7f60c1edb" rel="nofollow">http://gyazo.com/31da955d8af98f40b82789a7f60c1edb</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload