Use HTML5 tag audio to play audio with different clients

Source: Internet
Author: User

Disclaimer: iOS systems do not support FALSH, so HTML5 audio tags supported by each platform

<script>

Create an audio label

var audio = document.createelement ("audio");

Add Audio Property ID

Audio.id = "Audio";

Set the playback file path

AUDIO.SRC = "Sound/music.mp3";

Set whether to loop playback

Audio.loop = "loop";

Get current client environment information

var ua = Window.navigator.userAgent.toLowerCase ();

Determine the current environment and make appropriate processing

if (Ua.match (/iphone/i) = = "iphone" | | ua.match (/ipod/i) = = "ipod" | | ua.match (/ipad/i) = = "ipad") {

Currently an iOS-related environment, adding event Touchstart monitoring for a canvas node

document.getElementById ("Canvas"). AddEventListener ("Touchstart", function () {

Audio playback

Audio.play ();

});

}else if (ua.match (/android/i) = = "Android") {

Do not process the Android system

}else{

For non-iOS, Android systems, use the Listen Click event to

document.getElementById ("Canvas"). AddEventListener ("click", Function () {

Audio playback

Audio.play ();

});

}

</script>


This article is from the "Mirwangsir" blog, make sure to keep this source http://mirwangsir.blog.51cto.com/7723278/1565734

Use HTML5 tag audio to play audio with different clients

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: info-contact@alibabacloud.com 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.