我想加载一个 YouTube 视频,然后立即静音、播放、暂停和取消静音。在这样做时,我希望向用户展示一个没有大播放按钮的视频,并且底部有控件。为了做到这一点,我有以下代码:
<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,它看起来应该可以工作,但事实并非如此。