Added init version of audio support as poc.
This commit is contained in:
parent
87345c21ea
commit
b8c554f0e7
2 changed files with 17 additions and 0 deletions
|
@ -39,6 +39,11 @@ class App.Navigation extends App.Controller
|
||||||
@bind 'bell', (data) =>
|
@bind 'bell', (data) =>
|
||||||
if data is 'on'
|
if data is 'on'
|
||||||
@el.find('.bell').addClass('show')
|
@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
|
else
|
||||||
@el.find('.bell').removeClass('show')
|
@el.find('.bell').removeClass('show')
|
||||||
|
|
||||||
|
|
12
app/assets/javascripts/app/lib/app_post/audio.js.coffee
Normal file
12
app/assets/javascripts/app/lib/app_post/audio.js.coffee
Normal 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()
|
Loading…
Reference in a new issue