Last active
August 29, 2015 14:10
-
-
Save johnanthonyevans/014a98084b73ec89b282 to your computer and use it in GitHub Desktop.
Provides an audio layer for framerjs. Totally stolen from the framer source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copied mostly from the framer source which at this time is here https://github.com/koenbok/Framer/blob/master/framer/VideoLayer.coffee | |
class AudioLayer extends Layer | |
constructor: (options={}) -> | |
super options | |
@player = document.createElement("audio") | |
@player.setAttribute("preload", "auto") | |
# Make it work with .on and .off | |
# https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events | |
@player.on = @player.addEventListener | |
@player.off = @player.removeEventListener | |
@audio = options.audio | |
@_element.appendChild(@player) | |
@define "audio", | |
get: -> @player.src | |
set: (audio) -> @player.src = audio | |
audioLayer = new AudioLayer audio:"http://www.w3schools.com/html/horse.mp3" | |
# audioLayer.player.setAttribute("controls","true") | |
audioLayer.width = 300 | |
audioLayer.height = 300 | |
# Listen to audio events like play, ended. You can find all the listenable events here: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events | |
audioLayer.player.on "play", -> | |
print "audio.play" | |
audioLayer.player.on "ended", -> | |
audioLayer.player.play() # Loop | |
print "audio.ended" | |
# Bounce the audio on a click | |
audioLayer.on Events.Click, -> | |
audioLayer.player.play() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment