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); } }
To access it, open the Control Panel, and go to Hardware and Sound. Then, in the Sound section, click or tap the “Adjust system volume” link. Use the Volume Mixer window that pops up to set the desired sound level for the speakers, system sounds, or any open Windows apps.
Change your JavaScript to: function setHalfVolume() { var myAudio = document. getElementById("audio1"); myAudio. volume = 0.5; //Changed this to 0.5 or 50% volume since the function is called Set Half Volume ;) }
To do so, select the video clip you wish on which you want to change the volume, and then click on 'Edit'. Then, you will see the toolbar which contains a volume slider to mute the video by going from 100% to 0 as shown below. That's it. Now you can add the music or audio you wish to your video.
It's not a function, it's a property called volume
.
audio.volume = 0.2;
HTMLMediaElement volume MDN
i use:
let music = new audio({ loop: true, volume: 1, src: ['/yourSounds/music.mp3'] })
it is easer to type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With