Home  >  Article  >  Web Front-end  >  HTML5 returns the attribute of whether the audio/video has ended

HTML5 returns the attribute of whether the audio/video has ended

黄舟
黄舟Original
2017-11-08 14:00:453337browse

Example

Check whether videoplayback has ended:

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

Definition and usage

ended attribute returnsaudio/ Whether the video has ended.

If the playback position is at the end of the audio/video, the audio/video has ended.

Browser support

All major browsers support the ended attribute.

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

Syntax

audio|video.ended

Return value

Type Description
Boolean value true|false. Returns true if playback has ended. Otherwise return false.

Example

Check whether the video playback has ended:

<!DOCTYPE html> 
<html> 
<body> 

<p>
	<button onclick="hasVidEnded()" 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 hasVidEnded() { 
	alert(myVid.ended);
} 
</script> 

</body> 
</html>


The above is the detailed content of HTML5 returns the attribute of whether the audio/video has ended. 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