I know that i can create an audio object like this:
var audio = new Audio("test.wav");
And i know how i can play the audio:
audio.play();
I used the following for
loop to output all functions from audio
:
var myAudioObject = new Audio(); for (var key in myAudioObject) { if (typeof myAudioObject[key] === "function") { console.log(key); } }
But there is no setting for volume. Is it possible to change the volume in the audio object?
HINT
It was my fault. If i replace function
in my for loop with number
then i find volume.
var myAudioObject = new Audio(); for (var key in myAudioObject) { if (typeof myAudioObject[key] === "number") { console.log(key); } }
It's not a function, it's a property called volume
.
audio.volume = 0.2;
I use:
let music = new Audio({
loop: true,
volume: 1,
src: ['/yourSounds/music.mp3']
})
it is easer to type
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.