简体   繁体   English

静音事件javascript上的音频HTML5? 在MVC中

[英]Audio html5 on mute event javascript? In MVC

I need to find some event that fires,when i press mute button.On volumechange works only, when i change volume. 当我按下静音按钮时,我需要找到一些触发的事件。只有在更改音量时,音量更改才起作用。

  <audio id="volumeController" onvolumechange="changeVolume()"controls>
            <source src="~/Sounds/beep.mp3" type="audio/mpeg"/>
        </audio>

also i tried to use onclick and onchange events but instead of current volume,it sends always 1 instead of 0. 我也尝试使用onclick和onchange事件,但不是总是发送当前音量,而是总是发送1而不是0。

In HTML5 there isn't any mute event , when you click on mute and media gets muted it still counted as volumechange event .But there is another way that you can discern whether it's a mute or regular volumechage ; 在HTML5中没有任何静音事件,当您单击静音并且媒体被静音时,它仍被视为volumechange事件。但是您可以通过另一种方式来辨别它是静音还是常规音量调整; you can use muted property it gets set to true when you mute false otherwise 您可以使用muted属性,否则将其设置为true ,否则将其设置为false

var audio = document.getElementById('audio');

audio.addEventListener('volumechange',function(e){
  if(this.muted)
        console.log('Audio muted');
}, false);

demo: http://jsfiddle.net/8w0ppdf4/ 演示: http : //jsfiddle.net/8w0ppdf4/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM