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):
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.