Skip to content

Instantly share code, notes, and snippets.

@lime
Forked from wolfflow/player.coffee
Created April 26, 2014 15:02
Show Gist options
  • Save lime/11322309 to your computer and use it in GitHub Desktop.
Save lime/11322309 to your computer and use it in GitHub Desktop.
class Player
constructor: (@node, @src) ->
@init()
init: ->
@node.src = @src
@node.play()
event: (type) ->
Bacon.fromEventTarget(@node, type).map ".currentTarget"
seek: (pos) ->
@node.currentTime = pos
progress: ->
position = @event("timeupdate").map(".currentTime").toProperty()
duration = @event("loadedmetadata").map(".duration").toProperty()
duration.combine position, (duration, position) -> {duration, position}
player = new Player(document.getElementById("player"), "my-video.mp4")
player.progress().assign (x) -> console.log [x.position, x.duration].join("/")
player.event("ended").assign (x) -> console.log "ENDED"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment