Reputation: 205
I have an audio file audio
. on calling playaudio() function it plays.
i want to play audio when window opens.
how do i do it?
window.onload = function(playAudio();)
var audio = new Audio("https://s3.amazonaws.com/audio-experiments/examples/elon_mono.wav");
function playAudio() {
audio.volume = 0.5;
audio.play();
}
Upvotes: 1
Views: 67
Reputation: 2414
To reduce the volume to half, simply do:
audio.volume = 0.5;
Here is the documentation
To autoplay the audio, just do:
audio.autoplay = true;
The property can either be true
or false
. See here
Upvotes: 3
Reputation: 21
See here : https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volume
There is a property called volume that you can change like this :
audio.volume = value;
the expected value is of type double
Upvotes: 2