开发者

HTML5 audio on mobile: wait for playing

开发者 https://www.devze.com 2023-04-03 06:29 出处:网络
I use audio tag to play sound, here\'s code: <audio autoplay=\"autoplay\" controls=\"controls\">

I use audio tag to play sound, here's code:

<audio autoplay="autoplay" controls="controls">
   <source src="' + PathMp3 + '" type="audio/mp3" />
   <source src="' + PathOgg + '" type="audio/ogg" />
   Your browser does not support the audio element.
</audio>

Audio files are disposed on server. When I open html page on PC, audio starts to play immediately when I click on player.

However on mobile phone I tap on player and wait more than 30 seconds (sometimes 90secs!) before it starts to play. Very long delay.

Mobile internet isn't of course so fast as ordinary but it's 3G and the average size of audio file is 1.7 Mb, it isn't much.

Why it doesn't play audio while loadi开发者_JAVA百科ng? I need to start playing just after getting first bytes. How to do it?

Thanks


Your mobile browser will not play those files automatically, you have to tap on them to start playback.

This is a restriction put in place so random sites wont waste a 3g users bandwidth by playing huge audio files automatically.


<audio autoplay controls preload>
    <source src="' + PathMp3 + '" type="audio/mpeg" />
    <source src="' + PathOgg + '" type="audio/ogg" />
    Your browser does not support the audio element.
</audio>

Have you tried this way?

By the way, as far as I know mp3 has a MIME-Type of "audio/mpeg".

0

精彩评论

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