From b8c554f0e70834684d26b6429e1ec46962f9ecd6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 20 Mar 2014 09:50:36 +0100 Subject: [PATCH] Added init version of audio support as poc. --- .../javascripts/app/controllers/navigation.js.coffee | 5 +++++ .../javascripts/app/lib/app_post/audio.js.coffee | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 app/assets/javascripts/app/lib/app_post/audio.js.coffee diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 6b999fe77..f29a844ab 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -39,6 +39,11 @@ class App.Navigation extends App.Controller @bind 'bell', (data) => if data is 'on' @el.find('.bell').addClass('show') + App.Audio.play( 'https://www.sounddogs.com/previews/2193/mp3/219024_SOUNDDOGS__be.mp3' ) + @delay( + -> App.Event.trigger('bell', 'off' ) + 3000 + ) else @el.find('.bell').removeClass('show') diff --git a/app/assets/javascripts/app/lib/app_post/audio.js.coffee b/app/assets/javascripts/app/lib/app_post/audio.js.coffee new file mode 100644 index 000000000..18df30b58 --- /dev/null +++ b/app/assets/javascripts/app/lib/app_post/audio.js.coffee @@ -0,0 +1,12 @@ +class App.Audio + @play: ( url, volume = 0.1 ) -> + return if !window.Audio + audio = new window.Audio() + return if !audio.canPlayType + canPlay = audio.canPlayType('audio/mp3') + return if canPlay isnt 'maybe' and canPlay isnt 'probably' + $(audio).prop( 'src', url ) + audio.load(); + audio.preload = "auto"; + audio.volume = volume; + audio.play()