Oh hi there web section. :buddy:
I am making a website for an assignment at school. I want to have a YouTube video which can be changed by clicking on different images. I can do this with the YouTube API, but I have run into a problem when viewing the page locally.
First of all onYouTubePlayerReady() never seem to be called, so I tried doing
[code]document.getElementById("ytPlayer").loadVideoById(videoID);[/code]
But this fails too because getElementById("ytPlayer") doesn't have the function loadVideoById.
My code so far:
[code]// Update a particular HTML element with a new value
function updateHTML(elmId, value) {
document.getElementById(elmId).innerHTML = value;
}
// Loads the selected video into the player.
function loadVideo(videoID) {
if(ytplayer) {
ytplayer.loadVideoById(videoID);
}
}
// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
alert("An error occured of type:" + errorCode);
}
// This function is automatically called by the player once it loads
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("ytPlayer");
ytplayer.addEventListener("onError", "onPlayerError");
}
// The "main method" of this sample. Called when someone clicks "Run".
function loadPlayer() {
// The video to load
var videoID = "ylLzyHk54Z0"
// Lets Flash from another domain call JavaScript
var params = { allowScriptAccess: "always" };
// The element id of the Flash embed
var atts = { id: "ytPlayer" };
// All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
swfobject.embedSWF("http://www.youtube.com/v/" + videoID +
"&enablejsapi=1&playerapiid=player1",
"videoDiv", "480", "295", "8", null, null, params, atts);
}
function _run() {
loadPlayer();
}
google.setOnLoadCallback(_run);[/code]
Oh, and I haven't programmed javascript before (or web development at all, actually).
Edit:
Damn, it works perfectly in Googles playground (Test area for javascript), but it won't work locally. Does anybody know how I can make it run locally?
Do you have the SWFObject locally?
[QUOTE=Agent766;20807846]Do you have the SWFObject locally?[/QUOTE]
No. Should I?
Edit:
By the way, the player loads just fine, I just can't change the playing video.
I found the error. It's blocked by flash for security reasons (since flash is local and youtube is on the internet), so you have to change some security settings.
Sorry, you need to Log In to post a reply to this thread.