When my IFrame is displayed on a desktop browser, player.getCurrentTime() returns the correct time, ie. the time of the current frame in the video.
However, when displayed inside a WebView in Android, the initial video buffering takes longer, and the returned value corresponds to the time passed since the beginning of the buffering, not the playback time.
Any workaround?
Related
The rel parameter in YouTube API dictates whether or not related videos are shown at the end. When rel=0 the video reverts back to the thumbnail with a play button.
However on mobile (tested on iPhone / iPad / Fire Tablet) when the video goes back to the thumbnail it cannot be played a second time. It just does nothing.
I reported the issue to Google but nothing yet after a few days.
I had to resort to destroying the video and recreating it but this makes for a kind of nasty flickering.
My experience with YouTube issues is they never seem to end up fixing anything related to iOS - so I was wondering if there was any other kind of trick to prevent this.
Test page
The trouble with refreshing a webpage at a specific interval is that you dont know exactly when the video ends so you need to develop a method which the video player sends a signal when the video ends, which would then start the script to refresh the page. Otherwise you end up restarting it in the middle of the video. so personally, I would not even mess with refreshing the page. For Audio players it works ok because audio is smaller and streams more quicker. Video dont.... they always stop to buffer.
So YouTube API uses "Events" and "Listeners", so in particular, you need to design around the Event: "onStateChange".
When onStateChange = "ended" (zero) the video has ended, so then you reload the video player with the same video and set it to its Ready State again.
In theory its very easy you basically need to setup and control the entire video player through javascript. And the API gives examples on that.
http://code.google.com/apis/youtube/js_api_reference.html
http://grizzlyweb.com/webmaster/javascripts/refresh.asp
http://code.google.com/apis/youtube/forum/
Have a look at loop and playlist parameters as well. You can set playlist parameter to video ID and same video can be replayed using this.
So, it will be something like:
http://www.youtube.com/embed/{VIDEO_ID}?wmode=opaque&loop=1&version=3&playlist={VIDEO_ID}
Hope this helps!
Appears to have been fixed by YouTube.
I can now play the video multiple times (on multiple devices) without it getting stuck. Was too busy wondering why my question was getting so little attention that I forgot to check again to see if it was fixed ;-)
My website is running Bootstrap 3.0 and I have an intro video and full length video hosted on YouTube that I am trying to implement. The intro video autoplays when the page is loaded, and then I have a button that opens up a modal window with the full video with audio.
I would like to stop the video completely on close of the modal window so that if they click the button to open it again, the video starts from the beginning. Unfortunately, the stopVideo function doesn't seem to be working how I would expect. Basically, it's just pausing the video, so if I open the modal back up, the video starts playing right from where it left off.
How can I make it so that the video stops and starts from the beginning if it's reopened?
Here is my current code:
$('#myModal').on('show.bs.modal', function () {
$('#placeholder')[0].contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
$('#full')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
});
$('#myModal').on('hidden.bs.modal', function () {
$('#full')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
$('#placeholder')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
});
Thanks!
You can use seekTo to get back to the begining of the video when the modal is open.
An play the video after the seekTo
Doc from API
player.seekTo(seconds:Number, allowSeekAhead:Boolean):Void
Seeks to a specified time in the video. If the player is paused when
the function is called, it will remain paused. If the function is
called from another state (playing, video cued, etc.), the player will
play the video. The seconds parameter identifies the time to which the
player should advance.
The player will advance to the closest keyframe before that time
unless the player has already downloaded the portion of the video to
which the user is seeking. In that case, the player will advance to
the closest keyframe before or after the specified time as dictated by
the seek() method of the Flash player's NetStream object. (See Adobe's
documentation for more information.)
The allowSeekAhead parameter determines whether the player will make a
new request to the server if the seconds parameter specifies a time
outside of the currently buffered video data.
We recommend that you set this parameter to false while the user drags
the mouse along a video progress bar and then set it to true when the
user releases the mouse. This approach lets a user scroll to different
points of a video without requesting new video streams by scrolling
past unbuffered points in the video. When the user releases the mouse
button, the player advances to the desired point in the video and
requests a new video stream if necessary.
I also encountered this problem,spend hours digging into it. however I didn't find a sure reason, but the following reason may be it:
("stopVideo()") Stops and cancels loading of the current video.
and
Important: Unlike the pauseVideo function, which leaves the player in the paused (2) state, the stopVideo function could put the player into any not-playing state, including ended (0), paused (2), video cued (5) or unstarted (-1).
This is quoted from the YouTube API page
But I'm confused by this, because even if the background mechanism are not the same between stop and pause api, they act still identical(sometimes), so I'm still confused and curious about the real usage of stopVideo().
I'm building an article reading app for iphone.I'm parsing JSON content of article in uiwebview.
Some of the articles contains videos,But it does not display in the uiwebview.
JSON format for video is
<iframe src=\"\/\/www.youtube.com\/embed\/hdstrm\" height=\"360\" width=\"640\" allowfullscreen=\"\" frameborder=\"0\">
The uiwebview display empty space at the place of video frame
here is screen shot of uiwebview:
Displaying YouTube videos on iOS requires special treatment and is much less straight forward than you would expect (or hope). You can either display the entire YouTube page and let the user take it from there (or try to programmatically simulate a press on the play button), or you can "steal" the MP4 and play it using the media player.
The second option is better because it allows you to control the UI around the video and doesn't force you to display the entire YouTube page. However, it's important to stress that it requires quite a bit of work and is frowned upon by YouTube. In fact, they change the HTML structure of their pages every 2-3 months so that these mechanisms will break, and you won't be able to access the MP4 file directly without changing your code.
For more information on how to access the media file directly and play it, check out https://github.com/larcus94/LBYouTubeView
I'm trying to find a way of knowing when a Youtube video on an iPhone enters/exists fullscreen inside an HTML page. I am using Safari Mobile, not a UIWebView, the videos automatically go fullscreen as soon as they start playing.
Being obviously not on the youtube.com domain I cannot bind the webkitbeginfullscreen and webkitbendfullscreen on the <video> element within the iframe.
Is there any technique, even hacks, allowing me to query the video fullscreen state?
I think you'd have to detect iPhone or iPod user agent and then if the time changed on the video (via YouTube Javascript API) then you would have to assume it was playing.
Although, that only gets you equivalent beginfullscreen event reliably.
I have a YouTube IFrame player in a UIWebView. When the video is paused, the player keeps caching the video until its end. I'd like to limit the buffered part to no more than X seconds after the pausing/playing time point. How can I do that?
I haven't found any caching control in the IFrame API.
In the official iOS YouTube app, the caching seems to be limited to around 30s after the pausing/playing time.
There is no control over buffering through iFrame API. Buffering is usually determined with respect to viewer's own platform, device and connection and dynamically adjusted on the fly rather being controlled statically.
If that's the case for YouTube app or for the best of the user, that should be coming to the embed as well. You don't need to worry or try to control it.