How to set the loudness of HTML5 audio?

后端 未结 3 1068
情话喂你
情话喂你 2020-12-01 11:47

In an HTML5 game I\'m making, I play a \"thud\" sound when things collide. However, it is a bit unrealistic. No matter the velocity of the objects, they will always make the

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 12:08

    Use the audio element's volume property. From W3:

    The element's effective media volume is volume, interpreted relative to the range 0.0 to 1.0, with 0.0 being silent, and 1.0 being the loudest setting, values in between increasing in loudness. The range need not be linear. The loudest setting may be lower than the system's loudest possible setting; for example the user could have set a maximum volume.

    Ex: sounds[id].volume=.5;

提交回复
热议问题