Play Your Audio In A Web Browser (embed audio player using HTML5)
Why play sounds? Some user interfaces really benefit from audio feedback. In my case, it’s a feature so that people that use the Freckle Timer will get an audible ping every 15 minutes so they don’t forget that it’s still running (it’s optional of course!).
Anyway, script.aculo.us (version 1) actually came with experimental sound support, but that code is from a time when there was no HTML5, yet alone HTML5 audio yet. Let’s go with that code but update it to use HTML5 when possible.
Here’s look at various browsers and what they support: Internet Explorer
Surprisingly, it’s pretty easy to play a mp3 on IE, even on version 6. The little known bgsound element does it for you, no questions asked. On IE9, with all the amazing HTML5 support, you can also use an audio tag, but IE9 misreports that it can play mp4 files when it can’t.
Safari
Can play mp3′s and m4a’s just fine with the audio tag, but behold: On Windows, if QuickTime is not installed also, not only will it not play any codecs, but the audio tag simply doesn’t exist, and the Audio object in JavaScript doesn’t either.
Firefox Has support since 3.5, but it will only play OGG and WAVE files. Go figure. Chrome Has broad support and will play most stuff thrown at it. Also, no cross-platform differences. Mobile devices
You can’t auto-play sounds, so forget about playing sounds as part of the UI now. On some devices (namely recent iOS devices) you can play sounds as a result of a direct user interaction (e.g. tap). It’s out of the scope of this article really.
It all boils down to: When HTML5 is there, do this: First, you need mp3, mp4 and ogg versions of your sound.
Basically, this will attempt to play a sound through an audio tag, and knows about IE9′s problem of misreporting that it plays mp4s. If all else fails, it will still attempt to play the mp3 version of the sound.
When there’s no HTML5 around, do this 1. In case you’re on IE, use a bgsound element:
Hi, Its me Hafeez. A webdesigner, blogspot developer and UI/UX Designer. I am a certified Themeforest top Author and Front-End Developer. I'am business speaker, marketer, Blogger and Javascript Programmer.
0 comments:
Post a Comment