开发者

HTML5 AutoPlay mp3 on IPad

开发者 https://www.devze.com 2023-03-31 11:59 出处:网络
I am trying to Autoplay an mp3 file using html5 on ipad but its not working Here is my code <audio src=\"1.mp3\" autoplay=\"\" controls=\"\" onended=\"this.play()\"></audio&g开发者_如何转开

I am trying to Autoplay an mp3 file using html5 on ipad but its not working

Here is my code

<audio src="1.mp3" autoplay="" controls="" onended="this.play()"></audio&g开发者_如何转开发t;


The iPad does not support autoplaying of video and audio files. This is a design decision.


I found a way to auto-play video. I think is working on audio, also.

It works if you append/empty every time the video element from the div.

function addListeners()
{
    // loop for each list item
    $('#mscroll li').each(function looping(index)
    {
        // onclick...
        $(this).click(function onItemClick()
        {
            // empty left column and description
            $("#divplayer").empty();
            // append video tag
            $("#divplayer").append('<video width="'+video_width+'" height="'+video_height+'" controls="controls"><source src="'+videos_array[index].mp4+'" autoplay/></video>');
            $('video').get(0).play();
        });
    });
}

I have tested this on my Ipad, iOS 5.1.1


Here is a pretty detailed overview of mobile audio and tricks to make it work, created in 2013, so quite recent: http://pupunzi.open-lab.com/2013/03/13/making-html5-audio-actually-work-on-mobile/

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消