Add music video embed audio in HTML

Source: Internet
Author: User

To do H5 page, you need to add background music, the method is as follows

Mode one: <video controls= "" autoplay= "" name= "Media" ><source src= "Music" type= "Audio/mpeg" ></video>

This way the player is displayed.

Way two: <embed src= "music/we Don ' t talk Anymore.mp3" autostart= "true" loop= "true" hidden= "true" ></embed> this way master If there are many players supported. To some extent, the browser compatibility problem is resolved. Way three: <audio autoplay= "" loop= "" ><source src= "Http://" ></audio> this does not show the player. the <audio> tag is hidden by default. Added: Question 1: Apple Mobile Safari and do not play music issues: with <audio> add in after (iOS system) browsing page does not automatically play, click on the pause and then click Play Normal again, this means that the playback function is not a problem, The page will not be played automatically after the browser is opened with iOS, and the page can be played automatically with the Android phone, which proves that the code itself is not a problem, and then the relevant literature is checked, because iOS Safari restrictions do not allow audio AutoPlay, users must actively interact (for example, click) to play audio, so we can use a user interaction event to actively play audio should be able to solve the problem. Workaround:

1, using the interface provided: Wx.config and Wx.ready
First introduce JS file
<script src= " "></script>

Add the following code to the page

wx.config({    debug : false, // 这里为false    appId : ‘‘, // 以下随意填写即可 timestamp : (new Date()).getTime(), nonceStr : ‘‘, signature : ‘‘, jsApiList : [‘checkJsApi‘] });wx.ready(function() {; })

2:weixinjsbridgeready, this is the thing that can be done with this stuff.
The code is as follows:

var audo = document.getElementById(‘myAudio‘);;document.addEventListener(‘WeixinJSBridgeReady‘, function() {; }, false);
Question 2 $ ("#audio"). Play () error not a function 

Cause of Error: the Play () method belongs to the DOM object method, $ (' #audio ') for the jquery object

WORKAROUND: Convert the jquery object to a DOM object

or write directly to the native method: document.getElementById (' Music-audio '). Play ();

Mode four: <bgsound src= background music link address loop=-1>Way Five: <audio src= "music/we Don ' t talk Anymore.mp3" id= "AUD" autoplay= "AutoPlay" controls = "controls" preload= "auto" ></audio>


1, the use of autoplay= "AutoPlay", the background music will be opened in the Audio page will be automatically played immediately.

2. Use controls= "Controls" to display a display control, such as a play button, within the page.

3, use "loop=" loop ", is to be the background music repeated playback.

4, using preload= "Auto", the audio is loaded at the same time as the page load, and ready to play.

5, use src= "", that is, in the "" to add the background music to save the path, such as: src= "Web page production \03.mp3".

Note: If you want the play button to be hidden, use the following statement: control the display of the audio tag directly using the display of the CSS

Add music video embed audio in HTML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.