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

How to use the audio and video tags added by h5

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

Share

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

This article focuses on "how to use the new audio and video tags in h5". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the new audio and video tags of h5.

If you were asked to add audio resources to your web page, how would you achieve it?

Before the emergence of H6, we could insert video resources into our web page with the help of the iframe element. The code is as follows:

Document

The effect is as follows:

In addition, we can also use Html5 audio and video tags to introduce audio media resources into our web pages to increase the richness of our pages.

Tags define sounds, such as music or other audio streams. It contains an audio file in .mp3 or .ogg format, and you can place text content between the start tag and the end tag, so that the old browser can display information that does not support the tag, as follows:

The use of H6 audio tag is too low in your browser version.

The effect is as follows (chrome browser): add the controls attribute to the audio tag to display controls to the user, such as the play button; the loop attribute indicates that playback restarts whenever the audio ends.

The effect of audio tags varies from browser to browser:

Many trendy websites offer videos, and until now, there is still no standard for displaying videos on web pages. Today, most videos are displayed through plug-ins such as Flash. However, not all browsers have the same plug-in.

HTML5 specifies a standard way to include video through the video element. And the video element supports global attributes (such as class,id,title, style, etc.) and event attributes (such as onresize,onredo, etc.) in HTML.

Document Opps, your browser version is too low to support the playback of this video ~

Video attribute

You can also set the video window size

Switch playback URL (it is common to switch between ultra-high definition and smooth, different video addresses with different image quality)

Var video = document.getElementById ('test1') console.log (video.src) / / http://127.0.0.1:8001/test.mp4 absolute address. In DOM, the relative address / / video.src =' test-2.mp4' / / directly replaces the original video src setTimeout (() = > {video.src = 'test-2.mp4' / / when playing to 30s). Automatically switch videos}, 30000)

Switch the alternate address. Multiple source elements can be embedded in the video tag to switch the playback address. When the first video fails to load, the next video will be loaded automatically.

Var video = document.getElementById ('test2') setTimeout (() = > {console.log (video.currentSrc) / / http://127.0.0.1:8001/test-2.mp4}, 1000) / / HTTP failed to load, status code 404. The media resource http://127.0.0.1:8001/test3.mp4 failed to load. / / HTTP failed to load, status code 404. The media resource http://127.0.0.1:8001/test9.mp4 failed to load. At this point, I believe you have a deeper understanding of "how to use the new audio and video tags in h5". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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