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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745467352a4628973.html
评论列表(0条)