I’ve got a program which takes Youtube URLs from a database, and I’m having trouble with the Youtube javascript API.
In my codebehind, I’m calling the following code:
Table1.Rows(0).Cells(0).Text = "<object style=""height: 390px; width: 640px"" id=""ytplayer"">" & _
"<param name=""movie"" value=""https://www.youtube.com/v/UASyS-jUKKI?version=3&feature=player_embedded&controls=0&enablejsapi=1&showinfo=0&iv_load_policy=3&playerapiid=ytplayer"">" & _
"<param name=""allowfullscreen"" value=""true"">" & _
"<param name=""allowscriptaccess"" value=""always"">" & _
"<embed src=""https://www.youtube.com/v/UASyS-jUKKI?version=3&feature=player_embedded&controls=0&enablejsapi=1&showinfo=0&iv_load_policy=3&playerapiid=ytplayer"" type=""application/x-shockwave-flash"" allowfullscreen=""true"" allowscriptaccess=""always"" width=""425"" height=""344"" id=""ytplayer""></object>"
(where I’ll reference the sources to records in my database).
This embeds it on the page fine, and it plays, but I want to use API functions, which aren’t working for me.
var vid;
function onYouTubePlayerReady(id) {
vid = id;
var video = document.GetElementById(vid);
video.playVideo()
}
function play() {
var vobj;
if (vid) {
vobj = document.getElementById(vid);
alert(vobj);
vobj.playVideo();
}
}
<a href="javascript:void(0);" onclick="play();">Play</a>
I know that it’s successfully calling the ‘onYouTubePlayerReady’ function (and returning the ID), but play/pause/stop etc. aren’t working. Anybody know how to fix this?
It is running on a server, not locally.
Thanks
Both your
objectandembedtags have the sameID="ytplayer", which is not allowed in the DOM. Try changing one of them.