Home  >  Article  >  Web Front-end  >  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

黄舟
黄舟Original
2017-11-09 09:51:062283browse

Example

Get the current network status of video:

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

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

Return value

Type Description
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>

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!

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