开发者

control volume by javascript function

I have to play a music file on HTML page which is running on a开发者_开发问答ndroid, also need to control the volume by javascript function. Can someone give me any idea?


If you are using the HTML5 <audio> element, you can control the volume using the .volume. attribute. Set it to 1.0 for max volume, and 0.0 to mute it.

For example, this script will begin playing a file, then reduce its volume to 25% after a few seconds.

  <audio src="http://goo.gl/89jWZ" id="example"></audio>
  <script>
    var audioElement = document.getElementById("example");
    audioElement.play();

    setTimeout(function() {
      audioElement.volume = 0.25;
    }, 3000);
  </script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜