English 中文(简体)
播放 Youtube 视频时如何暂停背景音乐
原标题:How to pause background music when youtube video is played
  • 时间:2012-05-25 05:57:33
  •  标签:
  • jquery
  • html

我使用 HTML5 音频标签播放一些背景音乐, 页面上还有YouTube 视频。 当YouTube 视频播放时, 我无法找到如何自动停止背景音乐 。

<audio id="player" autoplay src="War drums.mp3"></audio>
    <div id="music">
<button id="play" onclick="document.getElementById( player ).play()"></button>
<button id="pause" onclick="document.getElementById( player ).pause()"></button>
<button id="up" onclick="document.getElementById( player ).volume+=0.1"></button>
<button id="down" onclick="document.getElementById( player ).volume-=0.1"></button>
    </div>
问题回答

您可能想要查看 < a href= > "https:// developmenters.google.com/youtube/js_api_ reference" rel=“ no follow” >YouTube JavaScript Player API 。

看起来你需要的东西 比如:

var youtubeplayer = document.getElementById( youtubeid );

youtubeplayer.addEventListener("onStateChange", function(e) {

   if (e === 1) {
       document.getElementById( player ).pause();
   } else {
       document.getElementById( player ).play();
   };

});

在使用之前,我先给AIP参考书读好一点。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签