单击取消静音按钮后如何将音量设置为特定值?

How to set volume to be at a specific value upon clicking unmute button?

我正在为我的视频使用 media player js,默认情况下我的视频是静音的,现在我希望在点击取消静音按钮时音量应该是 70%,

HTML

<div class="video">
   <video id="player1" muted autoplay controls preload="none">
      <source type="video/mp4" src="https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4" data-quality="SD" />
   </video>
</div>

这是JS

$('video').mediaelementplayer({
    features: ['playpause', 'current', 'progress', 'duration', 'volume', 'fullscreen', 'quality'],
    stretching: "responsive",
    enableAutosize: false,
    startVolume: 0.5,
    success: function(mediaElement, domObject) {
        mediaElement.setVolume(0.5);
        console.log(mediaElement);
    }
});

现在,当我点击取消静音按钮时,音量未设置为 0.5,

我需要做什么来解决这个问题?任何帮助或建议将不胜感激

寻找 'volumechnage' 事件将允许您执行此操作 - 请参阅下面的修改后的 Javascript,它在您的演示示例中测试时有效:

$('video').mediaelementplayer({
        features : ['playpause','current','progress','duration','volume','fullscreen','quality'],
  stretching : "responsive",
    enableAutosize : false,
   startVolume: 0.5,
    success: function (mediaElement, domObject) {
            mediaElement.setVolume(0.5);
            console.log(mediaElement);
            mediaElement.addEventListener("volumechange", function() {
                 mediaElement.setVolume(0.5)
                       }, false);
     }
});

更多关于 HTML5 媒体活动的文档: