admin管理员组文章数量:1429524
I am trying to save the volume of a playing music file in a cookie so when the page is reloaded, the volume the user chose last is maintained, rather than turning up super loud or whatever.
Here's my test code for the eventlistener:
var myAudio = document.getElementById("audio1");
myAudio.addEventListener('change',alert("Audio Volume Changed"),true};
However, it does not respond when I change the volume. I've searched and despite it being something I think is pretty practical, there's no information on it.
I am trying to save the volume of a playing music file in a cookie so when the page is reloaded, the volume the user chose last is maintained, rather than turning up super loud or whatever.
Here's my test code for the eventlistener:
var myAudio = document.getElementById("audio1");
myAudio.addEventListener('change',alert("Audio Volume Changed"),true};
However, it does not respond when I change the volume. I've searched and despite it being something I think is pretty practical, there's no information on it.
Share Improve this question edited Jul 9, 2013 at 0:39 JVE999 asked Jul 8, 2013 at 23:45 JVE999JVE999 3,52712 gold badges61 silver badges96 bronze badges 3-
3
1.
addEventListener
, notaddEventListner
2. Pass a function as the second argument; that code just callsalert()
. – Matt Ball Commented Jul 8, 2013 at 23:46 -
I can't believe I missed that typo. Anyway, I changed it to
myAudio.addEventListener('change',function () {alert("Audio Volume Changed");},true};
and nothing happens when I change the volume. – JVE999 Commented Jul 9, 2013 at 0:07 - I went ahead an edited the original, since that doesn't seem to be the real problem. I'm guessing it doesn't send a value on the volume change? That doesn't make sense since the audio element has a volume attribute... so, I don't know. – JVE999 Commented Jul 9, 2013 at 0:40
1 Answer
Reset to default 6You're looking for the "volumechange" event.
var audio = document.getElementById('sample');
audio.addEventListener('volumechange', function() {
console.log('changed.', arguments);
}, false);
I'm using the bubble phase(as opposed to capture) in this example.
http://jsfiddle/426E6/
http://www.w3/html/wg/drafts/html/master/embedded-content-0.html#event-definitions
本文标签: Javascript Add Event Listener for change in Audio VolumeStack Overflow
版权声明:本文标题:Javascript Add Event Listener for change in Audio Volume - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745467352a2659589.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论