1

我正在使用 HTML5 媒体 API 并坚持它的静音属性。我有这个静音按钮,每当我点击它时,我想用它来静音和取消静音特定视频的音频。问题是,只要我将其静音,它就可以工作,但我无法取消静音。类和标题值被正确设置为适当的值,但音量或图标图像没有变化。这是我的 jsfiddle 代码的链接http://jsfiddle.net/7AS3C/1/ 当我将代码上传到 jsfiddle 时,不会发生 CSS 问题。如果有人帮助我使用 javascript,我将不胜感激。

<div id="mediaplayer">
    <video id="media-video" controls>
        <source src='http://video.webmfiles.org/big-buck-bunny_trailer.webm' type='video/webm' controls>
    </video>
    <div>
        <div id="media-controls">
            <progress id="progress-bar" min="0" max="100" value="0"></progress>
            <button id='replay-button' class='replay' title='replay' onclick='replayMedia();'>Replay</button>
            <button id='play-pause-button' class='play' title='play' onclick='togglePlayPause();'>Play</button>
            <button id='stop-button' class='stop' title='stop' onclick='stopPlayer();'>Stop</button>
            <button id='volume-inc-button' class='volume-plus' title='increase volume' onclick='changeVolume("+");'>Increase volume</button>
            <button id='volume-dec-button' class='volume-minus' title='decrease volume' onclick='changeVolume("-");'>Decrease volume</button>
            <button id='mute-btn' class='mute' title='mute' onclick='toggleMute();'>Mute</button>
        </div>
    </div>
</div>

这是CSS

.unmute {
    width:45px;
    height:48px;
    background:url('mute.png');
    background-position: 0px 0px;
}
.mute {
    width:45px;
    height:48px;
    background:url('unmute.png');
    background-position: 0px 0px;
}

这是我的 javascript

muteBtn = document.getElementById('mute-btn');

function toggleMute() {
    if (player.muted = false) {
        changeButtonType(muteBtn, 'mute');
        player.muted = "true";
    } else if (player.muted = true) {
        changeButtonType(muteBtn, 'unmute');
        player.muted = "false";

    } else player.muted = "false";
}

function changeButtonType(buttonType, value) {
    buttonType.title = value;
    buttonType.innerHTML = value;
    buttonType.className = value;
}
4

1 回答 1

3

条件逻辑是分配而不是比较

if (player.muted = false) {

应该

if (player.muted === false) {

player.muted = "true"; 

应该

player.muted = true;

同样适用于错误块

于 2013-03-21T15:36:38.120 回答