最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to set volume on audio.play() - Stack Overflow

matteradmin9PV0评论

Nothing fancy here, I just want the audio to play at a desired volume level.

var audio = new Audio('mysound.mp3');
audio.play();

I assume there are parameters I can pass into audio.play, but I've had a hard time finding a good reference.

Thanks!

Nothing fancy here, I just want the audio to play at a desired volume level.

var audio = new Audio('mysound.mp3');
audio.play();

I assume there are parameters I can pass into audio.play, but I've had a hard time finding a good reference.

Thanks!

Share Improve this question asked Apr 10, 2017 at 1:39 DshizDshiz 3,3614 gold badges35 silver badges63 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You set volume like so

audio.volume = 0.75; // 75%

You can simply just do this:

audio.sound = .5

Before you call audio.play ()

Post a comment

comment list (0)

  1. No comments so far