4
votes

YouTube allows to use <iframe> to embed videos on sites in addition to flash based way of embedding. That has advantages especially for mobile devices. http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html

Unfortunatly i could not find any API documentation similar to flash based way like http://code.google.com/apis/youtube/js_api_reference.html

Is it possible to control programmatically the <iframe> based player using pure JavaScript, for example playing or pausing the video?

1

1 Answers

3
votes

https://developers.google.com/youtube/iframe_api_reference#Operations

We support a similar set of functions for the IFrame API as are currently supported for the JavaScript API.

Please refer to that document for a list of functions. Please note that the functions that deal with video bytes behave differently when HTML5 playback is used via the IFrame API. getVideoBytesTotal is hardcoded to return 1000. getVideoBytesLoaded will return a value between 0 and 1000. To calculate the fraction of the video that has been loaded you can divide the getVideoBytesLoaded value by the getVideoBytesTotal value, and that calculation will work regardless of whether HTML5 or ActionScript 3 playback is used.

Do note it is a experimental service which should not be used for production level applications.

Notice

Important: This is an experimental feature, which means that it might change unexpectedly.