简体   繁体   English

Html5 视频播放器自定义只显示播放和静音

[英]Html5 video player customize to only show play and mute

i'm trying to add some controls to a HTML5 video player that is used by Layerslider wordpress plugin.我正在尝试向 Layerslider wordpress 插件使用的 HTML5 视频播放器添加一些控件。 You can add some custom HTML to each layer and you can also add javascript.您可以向每个图层添加一些自定义 HTML,也可以添加 javascript。 But the mute button does not work :( Anything wrong with the code or does anyone have any suggestions on how to make this work?? I also tried loading the javascript on the page seperatly.但是静音按钮不起作用:(代码有什么问题,或者有人对如何使其工作有任何建议吗??我还尝试在页面上单独加载javascript。

Thanks in advance.提前致谢。

Related url: http://www.welzendesign.com/startransfer/相关网址: http : //www.welzendesign.com/startransfer/

    <video id="myVideo" width="50%" height="50%" autoplay loop>
        <source src="/startransfer/wp-content/uploads/2015/10/StarTransfer-promo-aanhanger.mp4" type="video/mp4">
    </video>

    <button class="mute-video">toggle</button>

        <style>

.mute-video {
            background:url(http://cdn.flaticon.com/png/64/60750.png) no-repeat center;
            background-size:32px;
            border:0;
            width:32px;
            height:32px;
            text-indent:-999px;
        }
        .unmute-video {
            background:url(http://cdn.flaticon.com/png/64/498.png) no-repeat center;
            background-size:32px;
        }
</style>

        <script>

 a"$("video").prop('unmuted', true);

        $(".mute-video").click(function () {
            if ($("video").prop('muted')) {
                $("video").prop('muted', false);
                $(this).addClass('unmute-video');

            } else {
                $("video").prop('muted', true);
                $(this).removeClass('unmute-video');
            }
            console.log($("video").prop('muted'))
        }); 

</script>

Inside the <script> tag copy/paste this (your code, which is correct), delete all the alerts and extra <script> tags and it should work just fine.<script>标签中复制/粘贴这个(你的代码,这是正确的),删除所有警报和额外的<script>标签,它应该可以正常工作。

        $("video").prop('unmuted', true);

        $(".mute-video").click(function() {
            if ($("video").prop('muted')) {
                $("video").prop('muted', false);
                $(this).addClass('unmute-video');

            } else {
                $("video").prop('muted', true);
                $(this).removeClass('unmute-video');
            }
            console.log($("video").prop('muted'))
        });

This was the correct answer if anyone else has this problem:如果其他人有这个问题,这是正确的答案:

function(element) {
    jQuery(document).on('click', '.mute-video', function (){
        if (jQuery("video").prop('muted')) {
            jQuery("video").prop('muted', false);
            jQuery(this).addClass('unmute-video');

        } else {
            jQuery("video").prop('muted', true);
            jQuery(this).removeClass('unmute-video');
        }
    });
}

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

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