Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

HTML5 Audio/Video tags, attributes, methods, event instance analysis

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian for you to introduce in detail the "HTML5 Audio/Video tags, attributes, methods, event instance analysis", detailed content, clear steps, details handled properly, I hope this "HTML5 Audio/Video tags, attributes, methods, event case analysis" article can help you solve doubts, following the editor's ideas slowly in-depth, together to learn new knowledge bar.

Tag attributes:

Src: the URL of Music

Preload: preloading

Autoplay: auto playback

Loop: loop playback

Controls: the control bar included in the browser

Html code

Get HTMLVideoElement and HTMLAudioElement objects

Js code

/ / audio can create objects directly through new

Media = new Audio ("http://www.abc.com/test.mp3")

/ / both audio and video can obtain objects through tags

Media = document.getElementByIdx_x ("media")

Media methods and properties:

Both HTMLVideoElement and HTMLAudioElement inherit from HTMLMediaElement

Js code

/ / error status

Media.error; / / null: normal

Media.error.code; / / 1. The user terminates 2. Network error 3. Decoding error 4.URL is invalid

/ / Network status

Media.currentSrc; / / returns the URL of the current resource

Media.src = value; / / returns or sets the URL of the current resource

Media.canPlayType (type); / / whether resources in a certain format can be played

Media.networkState; / / 0. This element is not initialized 1. Normal but not using network 2. Downloading data 3. No resources found

Media.load (); / / reload the resources specified by src

Media.buffered; / / returns the buffered region, TimeRanges

Media.preload; / / none: do not preload metadata: preload resource information auto:

/ / status of preparation

Media.readyState; / / 1:HAVE_NOTHING 2:HAVE_METADATA 3.HAVE_CURRENT_DATA 4.HAVE_FUTURE_DATA 5.HAVE_ENOUGH_DATA

Media.seeking; / / whether it is seeking or not

/ / playback status

Media.currentTime = value; / / the current playback position, which can be changed by assignment

Media.startTime; / / is generally 0, but not 0 if it is a streaming media or a resource that does not start from 0

Media.duration; / / the current resource length stream returns infinite

Media.paused; / / whether to pause

Media.defaultPlaybackRate = default playback speed of value;//, which can be set

Media.playbackRate = value;// current playback speed, change immediately after setting

Media.played; / / returns the area that has been played, TimeRanges. For this object, see below

Media.seekable; / / returns the region TimeRanges that can be seek

Media.ended; / / whether to end or not

Media.autoPlay; / / whether to play automatically

Media.loop; / / whether to play in a loop or not

Media.play (); / / playback

Media.pause (); / / pause

/ / Control

Does Media.controls;// have a default control bar?

Media.volume = value; / / Volume

Media.muted = value; / / mute

/ / TimeRanges (region) object

Number of TimeRanges.length; / / region segments

Start position of TimeRanges.start (index) / / paragraph index area

TimeRanges.end (index) / / the end of the index area

Events:

Js code

EventTester = function (e) {

Media.addEventListener (eQuery function () {

Console.log ((new Date ()). GetTime (), e)

});

}

EventTester ("loadstart"); / / the client starts to request data

EventTester ("progress"); / / the client is requesting data

EventTester ("suspend"); / / delayed download

EventTester ("abort"); / / the client initiatively terminates the download (not caused by an error)

EventTester ("error"); / / encountered an error while requesting data

EventTester ("stalled"); / / Network speed stall

Triggered when eventTester ("play"); / / play () and autoplay start playing

EventTester ("pause"); / / pause () triggers

EventTester ("loadedmetadata"); / / obtain the resource length successfully

EventTester ("loadeddata"); / /

EventTester ("waiting"); / / waiting for data is not an error

EventTester ("playing"); / / start playback

EventTester ("canplay"); / / can be played, but may be paused due to loading

EventTester ("canplaythrough"); / / can be played, and all the songs have been loaded

EventTester ("seeking"); / / searching

EventTester ("seeked"); / / search completed

EventTester ("timeupdate"); / / playback time change

EventTester ("ended"); / / end of playback

EventTester ("ratechange"); / / playback rate change

EventTester ("durationchange"); / / Resource length change

EventTester ("volumechange"); / / Volume change

Read here, the "HTML5 Audio/Video tags, attributes, methods, event instance analysis" article has been introduced, want to master the knowledge of this article also need to practice and use in order to understand, if you want to know more about the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report