Permalink
Browse files

HTML5 Audio (MP3) detection and playback if supported

  • Loading branch information...
1 parent 335fcb0 commit ce6dd9b435bdd7976e22ee2446b03f85dca6a665 Troy McCabe committed May 17, 2012
Showing with 24 additions and 5 deletions.
  1. +24 −5 src/view/pane.js
View
@@ -368,6 +368,11 @@ Candy.View.Pane = (function(self, $) {
* Chat toolbar for things like emoticons toolbar, room management etc.
*/
Toolbar: {
+ /** Boolean: supportsHTML5Audio
+ * Flag whether the browser supports the audio tag
+ */
+ supportsHTML5Audio: null,
+
/** Function: show
* Show toolbar.
*/
@@ -396,11 +401,25 @@ Candy.View.Pane = (function(self, $) {
* `playSound()` will only call this method if sound is enabled.
*/
onPlaySound: function() {
- var chatSoundPlayer = document.getElementById('chat-sound-player');
- try {
- chatSoundPlayer.SetVariable('method:stop', '');
- chatSoundPlayer.SetVariable('method:play', '');
- } catch (e) {}
+ // check for support if uninitialized
+ if (self.Chat.Toolbar.supportsHTML5Audio === null) {
+ // detection taken from http://diveintohtml5.com/everything.html
+ var a = document.createElement('audio');
+ self.Chat.Toolbar.supportsHTML5Audio = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
+ }
+
+ // use HTML5 if it's supported
+ if (self.Chat.Toolbar.supportsHTML5Audio) {
+ try {
+ new Audio(Self.getOptions().resources + 'notify.mp3').play();
+ } catch (e) {}
+ } else {
+ var chatSoundPlayer = document.getElementById('chat-sound-player');
+ try {
+ chatSoundPlayer.SetVariable('method:stop', '');
+ chatSoundPlayer.SetVariable('method:play', '');
+ } catch (e) {}
+ }
},
/** Function: onSoundControlClick

0 comments on commit ce6dd9b

Please sign in to comment.