The correct posture to play sound in the micro-trust browser and the audio label in the HTML5

Source: Internet
Author: User

The right posture seems to be wrong.

Status is

Wx.config ({
Configuration information
});
Wx.ready (function () {
MEDIA.SRC = "/project/shake-money/img/shake.mp3"
Media.play ();
});

Code can be put together, code separate, or call other JS SDK, it is not.
It's been tested for a long time and will never be implemented. Think of the former Weixinjsbridge, test a bit, unexpectedly became.

var media = document.getElementById ("MusicBox");
if (typeof Weixinjsbridge = = "Object" && typeof Weixinjsbridge.invoke = = "function") {
Weixinjsbridge.invoke (' Getnetworktype ', {}, function (res) {
To get e.err_msg here, all of the network types are included in this area.
alert (res.err_msg);
Media.play ();
});
}
The front end is so egg broken.
=========== above content April 15, 2016 ===========

In the actual project, you need to play the sound in the micro-trust browser. So I learned some relevant knowledge of playing sound in HTML5. IOS Safari does not allow AutoPlay audio and can only be triggered through user interaction.

Learn about the properties and time of basic sound playback, and start writing code, such as HTML:

<audio style= "Display:none" id= "MusicBox" preload= "metadata" controls autoplay= "false" ></audio>
JS Code:

var media = document.getElementById ("MusicBox");
if (!MEDIA.SRC) {
MEDIA.SRC = "/project/shake-money/img/shake.mp3"
}
Media.play ();
Can play normally in PC browser, but not in the micro-letter page. Tried a lot of posture, just can't play sound. Think of the micro-letter JS SDK, looking for a side also does not have the appropriate interface.

<script src= "Http://res.wx.qq.com/open/js/jweixin-1.0.0.js" ></script>
There is no way, simply in Wx.ready (function () {...}); Tried a bit, the result became! It is estimated that the micro-trust browser did some special processing.

Wx.config ({
Configuration information
});
Wx.ready (function () {
MEDIA.SRC = "Http://a.f265.com/project/shake-money/img/shake.mp3"
Media.play ();
});

Attached: Audio tags and attributes

Carefully studied the HTML5 key audio tags and attributes:

Attached: Media Events

Events triggered by media (such as video, images, and audio) (for all HTML elements, but are common in media elements such as <audio>, <embed>, , <object>, and <video >):


































































































Property value Description
Onabort Script The script to run when exiting.
Oncanplay Script A script that runs when a file is ready to start playing (the buffer is sufficient to start).
Oncanplaythrough Script A script that runs when the media is able to play to the end without buffering and stopping.
Ondurationchange Script A script that runs when the medium length changes.
Onemptied Script A script that runs when a failure occurs and the file is suddenly unavailable (such as when the connection is accidentally disconnected).
onended Script A script that runs when the media has reached the end (you can send a message like "Thank you for watching").
OnError Script Script that runs when an error occurs during a file load.
Onloadeddata Script A script that runs when media data has been loaded.
Onloadedmetadata Script A script that runs when metadata, such as resolution and length, is loaded.
Onloadstart Script A script that runs before the file starts to load and does not actually load any data.
OnPause Script A script that runs when the media is paused by a user or program.
Onplay Script A script that runs when the media is ready to start playing.
Onplaying Script A script that runs when the media has started playing.
OnProgress Script The script that is run when the browser is getting media data.
Onratechange Script A script that runs whenever the playback rate changes (for example, when the user switches to slow action or fast forward mode).
onReadyStateChange Script A script that runs whenever the ready state changes (the status of the ready state Monitoring media data).
Onseeked Script The script that runs when the seeking property is set to False, which indicates that the location has ended.
Onseeking Script The script that runs when the seeking property is set to True (indicates that the location is active).
Onstalled Script Script that runs when the media data is not retrieved by the browser for whatever reason.
Onsuspend Script Scripts that run when media data is terminated for whatever reason before the media data is fully loaded.
Ontimeupdate Script A script that runs when the playback position changes (for example, when a user quickly enters a different position in the media).
Onvolumechange Script A script that runs whenever the volume changes (including setting the volume to mute).
Onwaiting Script Run the script when the media has stopped playing but intends to continue playing (for example, when the media pauses buffered more data)

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.