Home > Web Front-end > H5 Tutorial > html5 returns the attribute networkState of the current network status (activity) of audio/video

html5 returns the attribute networkState of the current network status (activity) of audio/video

黄舟
Release: 2017-11-09 09:51:06
Original
2315 people have browsed it

Example

Get the current network status of video:

myVid=document.getElementById("video1");
alert(myVid.networkState);
Copy after login

Definition and usage

networkState property returns audio/ The current network status (activity) of the video.

Browser support

All major browsers support the networkState attribute.

Note: This attribute is not supported in Internet Explorer 8 or earlier browsers.

Syntax

audio|video.networkState
Copy after login

Return value

TypeDescription
Numeric value

represents the current network status of the audio/video element:

  • 0 = NETWORK_EMPTY - Audio/video has not been initialized

  • 1 = NETWORK_IDLE - The audio/video is active and the resource is selected, but the network is not being used

  • 2 = NETWORK_LOADING - The browser is downloading data

  • 3 = NETWORK_NO_SOURCE - Audio/video source not found

##Instance

Get Current network status of the video:

<!DOCTYPE html> 
<html> 
<body> 

<p>
	<button onclick="getNWState()" type="button">获得网络状态</button>
</p>
<video id="video1" controls="controls" autoplay="autoplay">
	<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 getNWState() { 
	alert(myVid.networkState);
} 
</script> 

</body> 
</html>
Copy after login

The above is the detailed content of html5 returns the attribute networkState of the current network status (activity) of audio/video. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template