我正在使用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;
}
答案 0 :(得分:2)
条件逻辑分配而不是比较
if (player.muted = false) {
应该是
if (player.muted === false) {
和
player.muted = "true";
应该是
player.muted = true;
同样适用于假块