Skip to content

Instantly share code, notes, and snippets.

@queso
Created June 8, 2013 16:47
Show Gist options
  • Save queso/5735833 to your computer and use it in GitHub Desktop.
Save queso/5735833 to your computer and use it in GitHub Desktop.
monitorPlay = (device, mediaFile) ->
loading = true
running = false
console.log("Starting play monitor")
status = Future.wrap(device.status)
while loading
res = status.wait()
console.log(res.inspect)
if res.duration > 0
console.log("Loaded")
loading = false
running = true
while running
console.log("Running")
res = status.wait()
if res.duration > 0
console.log("Updating play percentage")
percentage = new Number((res.position / res.duration)*100)
mediaFile.update({viewed_percentage: percentage.toPrecision(3)})
else
running = false
console.log("Finished playing #{mediaFile.name}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment