Use JavaScript to control the playback of html5<audio><video>elements and other functions

preface

HTML5 is a cross platform, simple and efficient technology. It provides <video> <audio> Such very convenient tags can be used to embed or use resources such as audio and video (of course, the specific decoding support is related to the browser). These tags also support HTML5 event attributes and global attributes.

Using js to control audio and other tags can achieve a simple music player effect.

Audio tag and video tag

about audio Labels and video The w3c has an easy to understand demonstration of how to use the tag.
Here is a simple example:

 <audio id=”playm” src=”./ Music/123. mp3 "controls=" controls ">Your browser does not support the html5 audio tag</audio>

Control audio tag with js

The method of using js to control the audio element is very simple. After obtaining the audio element, call the relevant API.

 //Get audio var auios=document.getElementById("playm"); //Call the following two functions (such as buttons) where necessary //Control playback auios.play(); //Pause audio.pause();

What can be done

Implement a simple page: click the "Play" button to start playing, and the button text changes to "Pause", waiting for another click. Click the button again to pause playing, and the button text changes to "Play", waiting for another click.

According to the above method, a simple page player can be implemented:

References

1. [Caption] [PIXIV]
2. [Picture] [minori] Goddess Alice # SPPL # 1

Zimiao haunting blog (azimiao. com) All rights reserved. Please note the link when reprinting: https://www.azimiao.com/1132.html
Welcome to the Zimiao haunting blog exchange group: three hundred and thirteen million seven hundred and thirty-two thousand

Comment

*

*