[英]HTML5 audio louder while playing
I've got a code like this: 我有这样的代码:
var upsound = new Audio('sound/upsound.mp3')
upsound.loop = true;
upsound.play();
I would like to get the volume louder while the audio is playing. 我想在播放音频时将音量调大一些。
Use the volume
property for this, which goes from 0.0 (mute) to 1.0 (full volume): 为此,请使用volume
属性,该属性从0.0(静音)到1.0(完整音量):
upsound.volume = 1.0;
Edit: 编辑:
If you want to set the volume up after a certain delay, you can simply use a timeout: 如果要在一定延迟后设置音量,则可以使用超时:
usound.volume = 0.0; // Start with no sound
setTimeout(function() {
usound.volume = 1.0; // Increase the volume after 2 seconds
}, 2000);
Volume attribute for audio should be the solution but until now, it seems like it is not been incorporated in any browsers. 音频的音量属性应该是解决方案,但是直到现在,似乎没有将其合并到任何浏览器中。 Check Browser Compatibility for Audio files . 检查音频文件的浏览器兼容性 。 You can use something like this which will give you controls to use during playing but through coding, it is not yet possible. 您可以使用类似这样的方法,使您可以在播放过程中使用控件,但是通过编码,尚无法实现。
<audio controls="controls">
<source src="foo.wav" type="audio/wav">
</audio>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.