admin管理员组文章数量:1279015
I am working with
howler.js 2.0
but cant seem to get a simple example of updating the volume working. Here some a sample code:
window.sound = new Howl({
src:'.mp3',
loop: true,
volume: 0.15
});
window.updateVolume = function(value) {
alert('before update volume:', window.sound.volume());
sound.volume = value;
alert('after update volume:', window.sound.volume());
}
I have tried both using volume() function
and just volume
property. None seem to work.
JsFiddle: /
What am I missing? Also, I noticed that if you click play
multiple times, multiple instances of the same sound start playing. I dont want that and hitting play
on a particular howl
instance should always work with that instance.
I am working with
howler.js 2.0
but cant seem to get a simple example of updating the volume working. Here some a sample code:
window.sound = new Howl({
src:'http://example./assets/audio/background.mp3',
loop: true,
volume: 0.15
});
window.updateVolume = function(value) {
alert('before update volume:', window.sound.volume());
sound.volume = value;
alert('after update volume:', window.sound.volume());
}
I have tried both using volume() function
and just volume
property. None seem to work.
JsFiddle: https://jsfiddle/umx2bdm8/
What am I missing? Also, I noticed that if you click play
multiple times, multiple instances of the same sound start playing. I dont want that and hitting play
on a particular howl
instance should always work with that instance.
1 Answer
Reset to default 9If you look at howler.js 2.0’s docs for volume
, it shows that volume
is a function, not an assignable property, and that you need to pass in the new volume as an argument to set the volume. So you need to do sound.volume(value)
instead of sound.volume = value
.
sound = new Howl({
src: 'http://www.hochmuth./mp3/Tchaikovsky_Rococo_Var_orch.mp3',
loop: true,
volume: 0.5
});
updateVolume = function(value) {
console.log('before update volume:', sound.volume());
sound.volume(value);
console.log('after update volume:', sound.volume());
}
<script src="https://cdnjs.cloudflare./ajax/libs/howler/2.0.0-beta13/howler.min.js"></script>
<button onclick="sound.play()">
Play
</button>
<button onclick="updateVolume(0.15)">
Change volume to 0.15
</button>
(I switched the volume values above for demo purposes, so listeners don’t have to worry whether the music will suddenly deafen them when they click the button.)
本文标签: javascripthowlerjs update volume of a soundStack Overflow
版权声明:本文标题:javascript - howler.js update volume of a sound - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741238864a2363566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论