var player; // You Tube player object
var theHistory = "";
var startTime = -1;
// When You Tube API is ready, create a new
// You Tube player in the div with id 'player'
function onYouTubeIframeAPIReady() {
player = new YT.Player('player_div',
{
videoId: 'P5_GlAOCHyE', // Load the initial video
playerVars: {
autoplay: 0, // Don't autoplay the initial video
rel: 0, // Don’t show related videos
theme: "light", // Use a light player instead of a dark one
controls: 1, // Show player controls
showinfo: 0, // Don’t show title or loader
modestbranding: 1 // No You Tube logo on control bar
},
events: {
// Callback when onReady fires
onReady: onReady,
// Callback when onStateChange fires
onStateChange: onStateChange,
// Callback when onError fires
onError: onError
}
});
}
// Callback specified to process the onReady event has been received
// so can proceed with creating and managing You Tube player(s)
function onReady(event) {
var time = getTime();
theHistory = "player ready " + time + "<br/>" + theHistory;
document.getElementById("history_div").innerHTML = theHistory;
console.log("player ready");
// make the interface visible since we're now ready to go
document.getElementById('ux').style.visibility = 'visible';
}
function submitLoadVideoById() {
var videoId = document.getElementById("loadVideoById").value;
player.loadVideoById({videoId: videoId});
}
// Log state changes
function onStateChange(event) {
var time = getTime();
var state = "undefiend";
switch (event.data) {
case YT.PlayerState.UNSTARTED:
state= "unstarted";
break;
case YT.PlayerState.ENDED:
state...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.