Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Audio: Chrome on Android doesn't automatically play song vs Chrome on PC does

I've made an HTML5 iPod.

You can try it here.

http://inventikasolutions.com/demo/iPod

On a PC, while using Chrome. If I navigate to a song, it starts playing automatically. But while using Chrome on Android it doesn't play the song. I have to hit the play/pause button again to play the audio.

Here is the code which runs, when you select the song to play:

audioPlayer.src=songurl[number];
audioPlayer.oncanplaythrough = "isAppLoaded";
audioPlayer.autoplay = "autoplay";
audioPlayer.addEventListener('ended',nextSong,false);
document.getElementById("player").appendChild(audioPlayer);

and here is the play/pause code.

        if (audioPlayer.paused)
        {
        audioPlayer.play();
        $("#pauseindicator").hide();
        $("#playindicator").show();
        }
        else
        {
        audioPlayer.pause();
        $("#pauseindicator").show();
        $("#playindicator").hide();
        }

Could it have some thing to do with the 'autoplay' variable? The default browser in Android plays the song immediately.

Thanks.

like image 657
Bilbo Baggins Avatar asked Sep 25 '12 17:09

Bilbo Baggins


People also ask

How do I Autoplay HTML music in Chrome?

Just add an invisible iframe with an . mp3 as its source and allow="autoplay" before the audio element. As a result, the browser is tricked into starting any subsequent audio file. Or autoplay a video that isn't muted.

Does autoplay work on Chrome?

Chrome no longer allows audio autoplay and video autoplay with sound. I expect other browsers to follow suit in the near future. I totally understand that video ads with sound that start playing out of nowhere are super annoying. They are the reason for this policy change.


2 Answers

In case someone bumps into this - Android version of Chrome in fact blocks autoplay function, but you can change settings of the browser. To do this, you have to enter chrome://flags and set Disable gesture requirement for media playback to on. It's impossible to force this setting via web, but if you're writing a dedicated web app like I did, you can use it.

like image 128
Kamil Szadkowski Avatar answered Oct 22 '22 22:10

Kamil Szadkowski


Please refer this link ...

http://code.google.com/p/chromium/issues/detail?id=138132

Chrome does not allow applications to play HTML5 audio without an explicit action by the user, similar to how it is handled by iOS, but differently than the stock Android browser handles it.

Autoplay is not honored on android as it will cost data usage.

like image 41
muhammed basil Avatar answered Oct 23 '22 00:10

muhammed basil