Javascript使用图像静音/取消静音视频

时间:2015-05-12 20:07:38

标签: javascript html html5 html5-video html5-audio

出于某种原因,它只是不起作用..我做错了什么? 我希望能够使用图像将视频静音和取消静音,这会改变视频是否静音。



 function mute() {
            var video = document.getElementById("bgvid");
         if (!video.muted) {
             document.getElementById('muteicon').src = "Images/muteicon.png";
            video.muted;
         }     else {
             document.getElementById('muteicon').src = "Images/soundicon.png";
             video.muted == false;
             }

        }

video#bgvid {
            margin-top: 30px;
            margin-bottom: 60px;

            width: 1280px; height: 720px;


            background-size: cover;

        }
        video { display: block; }

<video autoplay loop id="bgvid">
        <source src="newyork.mp4" type="video/mp4">
    </video>
    <br><br>
    <img alt="mute icon" src="Images/soundicon.png" id="muteicon" onclick="mute()">
    <script>
      </script>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:3)

您必须使用assign(=)运算符代替equality(==)运算符:

function mute() {
    var video = document.getElementById("bgvid");

    if (!video.muted) {
        document.getElementById('muteicon').src = "Images/muteicon.png";
        // video.muted <- not assigned to true
        video.muted = true;
    } else {
        document.getElementById('muteicon').src = "Images/soundicon.png";
        // video.muted == false <- wrong use of equality operator
        video.muted = false;
    }
}

你不能告诉API只需通过调用它就可以将属性设置为true

video.muted

您必须将属性分配给值:

video.muted = true

答案 1 :(得分:1)

当您尝试将视频静音时,您未将RACSignal* loginSignal = [[self authenticateWithUsername:username password:password] doNext:...]; RACSignal *resultSignal = [loginSignal then:^RACSignal* { return [self fetchProfile]; }]; return resultSignal; 属性设置为muted

true