HTML5视频已静音但仍在播放 [英] HTML5 Video muted but still playing
问题描述
标题几乎说明了一切.我有一个视频,到达页面后会自动开始播放.
Title pretty much says it all. I have a video which automatically starts playing when arriving on the page.
在HTML代码中,我设置了Mutant ="muted".奇怪的部分到了.查看控件时,它显然已静音,但音乐仍在播放并且可以听到.即使当我在W3Schools上观看HTML5视频示例时,它也会在静音时播放音乐.
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.
有什么办法,例如通过jQuery槽绕过这个吗?我在其中有一个jQuery行,该行将静音项粘贴到视频上,但这没有任何效果.
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.
以下是使用的HTML代码:
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>
希望您能帮助我. jQuery行如下:
Hope you can help me out. The jQuery line is as following:
$("video").prop('muted',true);
$("video").prop('muted', true);
先谢谢了.
推荐答案
我不确定在video
标记中定义muted
属性为何会发生故障.但是,这是您可以做的:
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 :
首先,从视频标签中删除muted="muted"
属性.保持其简单为:
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屋!