I copied the code for playing a youtube video, and then modified it to use an iframe that is in the body of the page. It should have played automatically, but instead, I had to click on the arrow in the video to get it going. I need to be able to start and stop iframe videos, and it would be nice if there was an example of jquery commands. But here is the code that does not work:
<html>
<body>
<iframe id="player" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1&origin=example.com"
frameborder="0">
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
events: {
'onReady': onPlayerReady
}
});
}
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
events: {
'onReady': onPlayerReady
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>
One possible problem is that I'm using an origin of 'example.com', instead of the origin of my local PC. Any help is appreciated - gid
player.stopVideo();
}
</script>
</body>
</html>
One possible problem is that I'm using an origin of 'example.com', instead of the origin of my local PC. Any help is appreciated - gid
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/Dsn0uMzlH5MJ.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment