Home  >  Article  >  Web Front-end  >  The attribute defaultMuted that sets or returns whether the audio/video is muted by default in HTML5

The attribute defaultMuted that sets or returns whether the audio/video is muted by default in HTML5

黄舟
黄舟Original
2017-11-08 11:08:107317browse

Example

SettingsVideoDefault mute:

myVid=document.getElementById("video1");
myVid.defaultMuted=true;

Definition and usage

defaultMuted PropertiesSet or returnAudio/Whether the video is muted by default.

Setting this property will only change the default mute state, not the current one. To change the current muted state, use the muted attribute.

Browser support

Only Google Chrome supports the defaultMuted attribute.

Syntax

Set the defaultMuted attribute:

audio|video.defaultMuted=true|false

Return the defaultMuted attribute:

audio|video.defaultMuted

Attribute value

Value Description
true Indicates that audio/video is muted by default.
false Default. Indicates that audio/video is not muted by default.

Technical Details

Return Value Boolean value. true|false
Default value: false

Instance

Set video default Mute:

<!DOCTYPE html> 
<html> 
<body> 

<p>
	<button onclick="getMuted()" type="button">该视频默认是静音的吗?</button>
	<button onclick="setToMuted()" type="button">把视频设置为默认静音,并重载视频</button>
</p>
<video id="video1" controls="controls">
	<source src="/kf51/demo/mov_bbb.mp4" type="video/mp4">
	<source src="/kf51/demo/mov_bbb.ogg" type="video/ogg">
	您的浏览器不支持 video 标签。
</video>

<script>
var myVid = document.getElementById("video1");
function getMuted() { 
	alert(myVid.defaultMuted);
} 
function setToMuted() { 
	myVid.defaultMuted = true;
	myVid.load()
} 
</script> 

</body> 
</html>

The above is the detailed content of The attribute defaultMuted that sets or returns whether the audio/video is muted by default in HTML5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn