HTML5视频静音但仍然播放 [英] HTML5 Video muted but stilly playing

查看:250
本文介绍了HTML5视频静音但仍然播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎说明了一切。我有一个视频在到达页面时自动开始播放。

在HTML代码中,我已将muted =muted。这里出现了怪异的部分。当看着这些控制器时,它显然是静音的,但是音乐仍在播放并且可以被听到。即使当我查看W3School上的HTML5视频示例时,它也会在静音时播放音乐。

有没有什么办法,例如用jQuery绕过这个?我有一个jQuery线,它粘在视频上,但没有任何效果。



以下是使用的HTML代码:

 < video id =videowidth =640pxheight =350pxautoplay =autoplayloop =loopcontrols =controlsmuted =muted> 
< source src =intouchables.f4vtype =video / mp4>
您的浏览器不支持视频标签。
< / video>

希望你能帮助我。 jQuery代码如下:



$(video)。prop('muted',true);

预先感谢。

解决方案

我不完全确定为什么静音属性在视频标签中定义时出现故障。但是,您可以这样做:首先,从视频中移除 muted =muted属性标签。将其保留为:

 < video id =videowidth =640pxheight =350pxautoplay = autoplayloop =loopcontrols =controls> 
< source src =intouchables.f4vtype =video / mp4>
您的浏览器不支持视频标签。
< / video>

现在,定义一个加载页面时将视频静音的函数。

  window.onload = function(){
var element = document.getElementById('video');
element.muted =静音;
}

我验证了这一点, b

Title pretty much says it all. I have a video which automatically starts playing when arriving on the page.

In the HTML code I have put muted="muted". And here comes the weird part. When looking at the controls it clearly is muted, but the music is still playing and can be heard. Even when I looked at the HTML5 Video example on W3Schools it plays the music while muted.

Is there any way, trough jQuery for example to bypass this? I have a jQuery line in it which stick the muted to the video but that has no effect.

Here is the HTML code is use:

<video id="video" width="640px" height="350px" autoplay="autoplay" loop="loop" controls="controls" muted="muted">
            <source src="intouchables.f4v" type="video/mp4">
            Your browser does not support the video tag.
        </video>

Hope you can help me out. The jQuery line is as following:

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

Thanks in advance.

解决方案

I'm not entirely sure as to why the muted attribute is malfunctioning when defined within the video tag. However, this is what you can do :

Firstly, remove the muted="muted" attribute from the video tag. Keep it simply as :

<video id="video" width="640px" height="350px" autoplay="autoplay" loop="loop" controls="controls">
    <source src="intouchables.f4v" type="video/mp4">
    Your browser does not support the video tag.
</video>

Now, define a function that on loading of the page, mutes the video.

window.onload = function () {
    var element = document.getElementById('video');
    element.muted = "muted";
}

I have verified this, and it works.

这篇关于HTML5视频静音但仍然播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆