Pause youtube video, youtube api

Use player.playVideo(); (resume) and player.pauseVideo(); (pause) once the player is ready: http://jsfiddle.net/4WPmY/6/ function onYouTubePlayerAPIReady() {     player = new YT.Player(‘player’, {         height: ‘315’,         width: ‘560’,         videoId: ‘bpOR_HuHRNs’,     });     document.getElementById(‘resume’).onclick = function() {         player.playVideo();     };     document.getElementById(‘pause’).onclick = function() {   … Read more

YouTube Player API: How to get duration of a loaded/cued video without playing it?

Solution 1 You can use YouTube Data API to access most of the information about the video, including duration: <script type=”text/javascript”> function youtubeFeedCallback(json){ document.write(json[“data”][“duration”] + ” second(s)”); } </script> <script type=”text/javascript” src=”http://gdata.youtube.com/feeds/api/videos/4TSJhIZmL0A?v=2&alt=jsonc&callback=youtubeFeedCallback&prettyprint=true”></script> Demo here When using jQuery you can use $.getJSON() to make things easier. Solution 2 Seems like YouTube JavaScript API v3 allows you … Read more

How to pause a YouTube player when hiding the iframe?

The easiest way to implement this behaviour is by calling the pauseVideo and playVideo methods, when necessary. Inspired by the result of my previous answer, I have written a pluginless function to achieve the desired behaviour. The only adjustments: I have added a function, toggleVideo I have added ?enablejsapi=1 to YouTube’s URL, to enable the … Read more

YouTube iframe API: how do I control an iframe player that’s already in the HTML?

Fiddle Links: Source code – Preview – Small version Update: This small function will only execute code in a single direction. If you want full support (eg event listeners / getters), have a look at Listening for Youtube Event in jQuery As a result of a deep code analysis, I’ve created a function: function callPlayer … Read more