Javascript 如何使用静音道具取消静音 html5 视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39041960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to unmute html5 video with a muted prop
提问by ?zgür Ersil
I've created a simple video block with muted (for mobile autostart) but now i can not change the mute state...
我创建了一个带有静音(用于移动自动启动)的简单视频块,但现在我无法更改静音状态...
I used that repository, fiddle link would be great.
我使用了那个存储库,小提琴链接会很棒。
So far i've tried this with no luck.
到目前为止,我已经尝试过这个,但没有运气。
HTML
HTML
<video width="640" height="264" muted autoplay webkit-playsinline src="'+videoURL+'"></video>'
JS
JS
$(document).on("click",".containerVolume",function(e){
if(isMuted){
$('video').prop('muted', false);
}
else{
$('video').prop('muted',true);
}
});
var videos = document.querySelectorAll('video');
if (location.search === '?enabled=false')
{
} else if (location.search === '?enabled=true') {
enableVideos(false);
} else {
enableVideos();
}
function enableVideos(everywhere) {
for (var i = 0; i < videos.length; i++) {
window.makeVideoPlayableInline(videos[i], !videos[i].hasAttribute('muted'), !everywhere);
}
}
回答by Glen Despaux Jr
Try this:
尝试这个:
function toggleMute() {
var video=document.getElementById("myVideo");
video.muted = !video.muted;
}
Check example here
在此处检查示例
If your own code is not working, try adding an id
to your video/element you want the click to register on and using:
如果您自己的代码不起作用,请尝试在id
您希望点击注册的视频/元素中添加并使用:
var video=document.getElementById("myVideo") ;
$(video).on("click", function(e){
video.muted = !video.muted;
});
回答by Kevin Jantzer
You should use videoEl.muted
你应该使用 videoEl.muted
var video = document.getElementById('video');
function toggleMute(){
video.muted = !video.muted;
}
<video id="video" width="300" controls muted src="http://www.w3schools.com/html/mov_bbb.mp4"></video>
<br><br>
<a onclick="toggleMute()">Toggle Mute</a>
回答by B.A.B.
You could simply mute/unmute with
你可以简单地静音/取消静音
document.getElementById("theIdOfYourVideoGoesHere").volume=0;
and
和
document.getElementById("theIdOfYourVideoGoesHere").volume=1;
(This thread appears to be two years old but today it was the number one top result in my google search)
(这个线程似乎已经两年了,但今天它是我谷歌搜索中排名第一的结果)
Bilgisayar ne bilgiden anlar ne sayg?dan. ?ünkü o cans?z bir düzenektir. O kadar.
Bilgisayar ne bilgiden anlar ne sayg?dan。?ünkü o cans?z bir düzenektir。哦卡达尔。