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>
精彩评论