HTML - attributes - onplay

revision:


Content

"onplay: attribute : when the video/audio has started to play syntax some examples


"onplay: attribute : when the video/audio has started to play

top

The onplay event occurs when the audio/video has been started or is no longer paused.

Supported HTML tags: <audio> and <video>.


syntax

top

<element onplay="script"></element >

script: this attribute contains a "single value script", which works when the onplay event attribute is called


some examples

top

Press play.

codes:
                    <div>
                        <p class="spec">Press play.</p>
                        <video style="margin-left:3vw;" width="400" height="auto" controls onplay="playV()">
                            <source src="../../pics/Wuzhen-20-10_02.mp4" type="video/mp4">
                            Your browser does not support HTML5 video.
                        </video>
                        <p id="vid-1" style="color:red"></p>
                    </div>
                    <script>
                        function playV() {
                        document.getElementById("vid-1").innerHTML = ("The video has started to play");
                        }
                    </script>
                

Press play.

codes
                    <div>
                        <p class="spec">Press play.</p>
                        <audio style="margin-left:3vw;" controls onplay="playA()">
                        <source src="../../pics/horse.wav" type="audio/wav">
                        Your browser does not support the audio element.
                        </audio>
                        <p id="aud-1" style="color:red"></p>
                    </div>
                    <script>
                        function playA() {
                            document.getElementById("aud-1").innerHTML = ("The audio started to play");
                        }
                    </script>