oncanplaythrough 事件


oncanplaythrough Event

Instance

<!DOCTYPE html> 
<html> 
<head>
<meta charset="utf-8">
</head>
<body> 

<video controls oncanplaythrough="myFunction()">
	<source src="mov_bbb.mp4" type="video/mp4">
	<source src="mov_bbb.ogg" type="video/ogg">
	您的浏览器不支持 HTML5 video 元素。
</video>
<script>
function myFunction() {
    alert("无需停顿可直接播放视频");
}
</script>

</body> 
</html>

Run Instance»

Click "Run Instance" button to view an online instance

More examples are included at the bottom of this article.


Definition and usage

The oncanplaythrough event is triggered when the video/audio (audio/video) can be played normally without pausing and buffering.

During the video/audio (audio/video) loading process, the triggering sequence of events is as follows:

  1. onloadstart
  2. ondurationchange
  3. onloadedmetadata
  4. onloadeddata
  5. onprogress
  6. oncanplay
  7. oncanplaythrough

##Browser support

The number in the table indicates the version number of the first browser that supports this event.

event##oncanplaythrough





Yes9.0YesYesYes
##Syntax

HTML:

< ;

element
oncanplaythrough="
myScript">Try itJavaScript:

object
.oncanplaythrough=function(){
myScript}; Try itIn JavaScript, use the addEventListener() method:

object
.addEventListener("canplaythrough",
myScript); Try it
Note:
Internet Explorer 8 and earlier IE versions do not support addEventListener( ) method.

Technical details


Whether bubbling is supported:NoCan be canceled:NoEvent type:Event <audio>, <video>
##Supported HTML tags:
##More examples

Examples

<!DOCTYPE html> 
<html> 
<head>
<meta charset="utf-8">
</head>
<body> 

<audio controls oncanplaythrough="myFunction()">
    <source src="horse.ogg" type="audio/ogg">
    <source src="horse.mp3" type="audio/mpeg">
    您的浏览器不支持 audio 元素。 
</audio>
<script>
function myFunction() {
    alert("无需停顿可直接播放视频");
}
</script>

</body> 
</html>

Run Instance»

Click the "Run Instance" button to view the online instance

##