Javascript Add Event Listener for change in Audio Volume - Stack Overflow

I am trying to save the volume of a playing music file in a cookie so when the page is reloaded, the vo

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, not addEventListner 2. Pass a function as the second argument; that code just calls alert(). – 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
Add a ment  | 

1 Answer 1

Reset to default 6

You'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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745467352a4628973.html

相关推荐

  • Javascript Add Event Listener for change in Audio Volume - Stack Overflow

    I am trying to save the volume of a playing music file in a cookie so when the page is reloaded, the vo

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信