HTML oncanplaythrough Event Attribute

Description

The event attribute oncanplaythrough is triggered when the browser can start playing the selected media file to the end without the need to stop for further buffering.

Syntax

<element oncanplaythrough="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

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

<audio id="myAudio" controls oncanplaythrough="myFunction()">
  <source src="audio.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<script>
function myFunction() {
    alert("Audio file ready to play without buffering");
}
</script> 

<p>Demonstration of the "oncanplaythrough" attribute in the AUDIO element.</p>

</body>
</html>

Supported Tags

<audio> and <video>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
XXYesYesXX
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesXXX