HTML - attributes - oncanplay

revision:


Content

"oncanplay" attribute : when the browser start playing syntax some examples


"oncanplay" attribute : when the browser start playing .

top

The oncanplay attribute defines a script to run when the browser can start playing the specified media (when it has buffered enough to begin).
The oncanplay attribute is part of the event attributes, and can be used on the following elements: <audio>, <embed>, <object>, <video>.


syntax

top

<audio oncanplay="script"></audio>

<embed oncanplay="script"></embed>

<object oncanplay="script"></object>

<video oncanplay="script"></video>

script: the script to be run on oncanplay.


some examples

top
code:
                        <audio style="margin-left:3vw;" id="myAudio" controls oncanplay="playAudio()"> 
                            <source src="../../pics/horse.wav" type="audio/wav">
                            Your browser does not support the audio element.
                        </audio>
                        <script>
                            function playAudio() {
                            alert("Can start playing the audio");
                            }
                        </script> 
                    
code
                    <video style="margin-left:3vw;" id="myVideo" width="320" height="176" 
                        controls oncanplay="playVideo()">
                         <source src="../../pics/Wuzhen-20-10_02.mp4" type="video/mp4">
                        Your browser does not support HTML5 video.
                    </video>
                    <script>
                        function playVideo() {
                        alert("Can start playing video");
                        }
                    </script>