I have a web app that uses the HTML5 <audio>
tag and for some reason, while it works fine on Windows and Mac PCs, it doesn't work on iOS and Android.
Here's a relevant snippet of my code:
Javascript:
var audioElement = document.querySelector('#audioplayer');
var source = document.querySelector('#mp3');
source.src = tokObject._url;
audioElement.load();
audioElement.play();
HTML:
<center>
<audio id="audioplayer" style="width:480px;">
<source id="mp3" src="random-placeholder" type="audio/mp3" />
</audio>
</center>
Bookmark this question. Show activity on this post. I have a web app that uses the HTML5 <audio> tag and for some reason, while it works fine on Windows and Mac PCs, it doesn't work on iOS and Android. Here's a relevant snippet of my code:
HTML5 Audio on desktop browsers is a mess. But you haven't experienced true pain and suffering until you try to get HTML5 audio done on mobile devices. This article is a follow-up to my talk at the Barcamp in Salzburg in March and was inspired by Chris Heilmans tweets on that topic a few days ago.
So the “advantage” of HTML5 delegation, just putting simple <audio> tags on the page and leaving implementers to take care of all the rest, which should bring optimized user experiences, actually doesn’t work. Do sounds – or better, even a sad, single sound – autoplay on loading a page on mobile?
This story starts when we had to provide audio to an HTML5 game we were building. The game is for mobile browsers, actually a limited and updated range of mobile browsers: Safari for iOS 6+, and the stock browser (i.e. the default browser) for Android 4+.
You normally can't autoplay audio or video files on mobile devices, this is often a restriction by the OSes such as Android and iOS to stop sites from downloading huge media files and autoplaying them.
If such code is called from within a click or touch handler, it will probably work, but not the way you are currently doing it.
Also, the <center>
element has been deprecated and you shouldn't use it anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With