Skip to content

Instantly share code, notes, and snippets.

@wolfflow
Last active December 19, 2015 22:29
Show Gist options
  • Save wolfflow/6027790 to your computer and use it in GitHub Desktop.
Save wolfflow/6027790 to your computer and use it in GitHub Desktop.
HTML5 Video + Bacon.js
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