我想加載YouTube視頻,然後立即靜音,播放,暫停和取消靜音。在這樣做的時候,我希望向用戶展示一個沒有大的播放按鈕的視頻,並且底部有控件。爲了做到這一點,我有以下代碼:爲什麼YouTube上的iframe播放器在加載時不會調用YouTubePlayerReady?
<script type="text/javascript">
function onYouTubePlayerReady(playerid)
{
mutePlayPauseUnmute(playerid);
}
function onYouTubePlayerAPIReady(playerid)
{
mutePlayPauseUnmute(playerid);
}
function onYouTubeIframeAPIReady(playerid)
{
mutePlayPauseUnmute(playerid)
}
function onPlayerReady(playerid)
{
mutePlayPauseUnmute(playerid)
}
function mutePlayPauseUnmute(playerid)
{
var player = document.getElementById(playerid);
player.mute();
player.playVideo();
player.pauseVideo();
player.unMute();
}
</script>
<iframe id="quotedVideo1" type="text/html" width="246" height="160" src="https://www.youtube.com/embed/NWHfY_lvKIQ?modestbranding=1&rel=0&showinfo=0&autohide=1&iv_load_policy=3&theme=light&enablejsapi=1&playerapiid=quotedVideo1" frameborder="0"> <!-- Magic Comment --> </iframe>
然而,經檢查,既不onYouTubePlayerReady
,onYouTubePlayerAPIReady
,onYouTubeIframeAPIReady
,onPlayerReady
,也不mutePlayPauseUnmute
是不斷調用。 我做錯了什麼?根據https://developers.google.com/youtube/js_api_reference#onYouTubePlayerReady它看起來應該工作,但它不。
值得注意的是:「玩家必須至少200px x 200px。」 – 2013-02-21 18:53:06
我知道......客戶要求它完全是這個尺寸:/ – Supuhstar 2013-02-21 23:12:23