Google Product Forums

Re: Iframe API issue, only in Opera Browser


Klementine Jul 7, 2012 8:53 PM
Posted in group: YouTube
OH - also you need to specify <!DOCTYPE> and <meta .....
in your header section or you will run into trouble some browsers - especially IE.

Here is the modified code which should work - fill in your other URL parameters as you see fit.

K-)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=unicode' />
<meta http-equiv='X-UA-Compatible' content='IE=9' />

</head>
<body>

<iframe id="player" width="640" height="390" frameborder="0" src="http://www.youtube.com/embed/u1zgFlCw8Aw?enablejsapi=1&autoplay=1"></iframe>

<script type="text/javascript">
var tag = document.createElement('script');
tag
.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag
.parentNode.insertBefore(tag, firstScriptTag);

var player;
function onYouTubePlayerAPIReady() {
player
= new YT.Player('player', {
events
: { 'onReady': time,
}
});
}

function time() {
document
.getElementById('duration').innerHTML = player.getDuration();
var int = self.setInterval('current()',500);
}
function current() {
document
.getElementById('current').innerHTML = player.getCurrentTime();
}

function play() {
player
.playVideo();
}

function pause() {
player
.pauseVideo();
}

function replay() {
player
.seekTo(0, true);
player
.playVideo();
}

function stop() {
player
.seekTo(0, true);
player
.stopVideo();
}

</script>
<br>

<a href="javascript:void(0);" onclick="replay();">Replay</a>
&bull;
<a href="javascript:void(0);" onclick="play();">Start</a>
&bull;
<a href="javascript:void(0);" onclick="pause();">Pause</a>
&bull;
<a href="javascript:void(0);" onclick="player.setVolume(50);">50</a>

<br>

<span id="current"></span> | <span id="duration"></span>

</body>
</html>

....... Plus I modified player.seekTo( ) because you should explicitly specify true or false for allowseekahead.