Mobile-H5 Audio playback issues

Source: Internet
Author: User

Recently due to new product requirements, the need to open the H5 page on the mobile side, and the ability to play audio automatically, during the development process encountered the following problems:
1.IOS device cannot respond to "Loadeddata" event

Mode 1
var audio = new Audio (SRC);
Audio.addeventlistener ("Loadeddata", function () {
    audio.play ();
    Start playback status processing
});

Mode 2
var audio = new Audio (SRC);
Audio.play ();

After testing, the above mode 1 does not play in the iOS device, mode 2 can play normally, the process of processing audio loading over effect will encounter problems, do not know when the audio load is complete, and start playback, the solution is as follows:

var playerhandle = setinterval (function () {

    if (Audio.currenttime > 0 &&!isnan (audio.duration)) {
        // Has started playing, processing the corresponding logic
        clearinterval (playerhandle);}
}, 0)

It is also important to note that if you need to control the playback progress, the length of the audio audio.duration must start playing, that is, Audio.currenttime > 0 o'clock gets, otherwise it will not be accurate.
2.h5 page loading finished can not be automatically played, set AutoPlay properties, audio tag add click event, and so on, because the mobile side webview have security restrictions, prohibit autoplay and other uncontrolled behavior, must be triggered by the user touch, To play, and finally the problem is solved by the mobile partner: The client has set up a security-related property to implement audio AutoPlay.

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.