Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set volume of audio object?

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);     }  }
like image 561
Black Avatar asked May 09 '16 12:05

Black


People also ask

How do I adjust the sound volume?

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.

How do I lower the volume of a song in HTML?

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 ;) }

How do I adjust the volume on a video file?

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.


2 Answers

It's not a function, it's a property called volume.

audio.volume = 0.2; 

HTMLMediaElement volume MDN

like image 166
Alexander Kravets Avatar answered Oct 02 '22 15:10

Alexander Kravets


i use:

let music = new audio({     loop: true,     volume: 1,     src: ['/yourSounds/music.mp3'] }) 

it is easer to type

like image 23
Solomon Kruse Avatar answered Oct 02 '22 14:10

Solomon Kruse