Added init version of audio support as poc.

This commit is contained in:
Martin Edenhofer 2014-03-20 09:50:36 +01:00
parent 87345c21ea
commit b8c554f0e7
2 changed files with 17 additions and 0 deletions

View file

@ -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')

View file

@ -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()