Bind to events after movie is loaded

This commit is contained in:
Marcin Kulik 2012-03-13 21:36:35 +01:00
parent 7f019e6918
commit ca38cc20e7
2 changed files with 14 additions and 11 deletions

View File

@ -2,7 +2,7 @@ class AsciiIo.Movie
MIN_DELAY: 0.01 MIN_DELAY: 0.01
SPEED: 1.0 SPEED: 1.0
constructor: (@model, @autoPlay) -> constructor: (@model) ->
@reset() @reset()
@startTimeReporter() @startTimeReporter()
_.extend(this, Backbone.Events) _.extend(this, Backbone.Events)
@ -22,8 +22,6 @@ class AsciiIo.Movie
@model.fetch @model.fetch
success: => success: =>
@trigger('movie-loaded', @model) @trigger('movie-loaded', @model)
if @autoPlay
@play()
timing: -> timing: ->
@model.get('stdout_timing_data') @model.get('stdout_timing_data')

View File

@ -1,7 +1,8 @@
class AsciiIo.PlayerView extends Backbone.View class AsciiIo.PlayerView extends Backbone.View
initialize: (options) -> initialize: (options) ->
@movie = new AsciiIo.Movie(@model, options.autoPlay) @movie = new AsciiIo.Movie(@model)
@movie.on 'movie-loaded', @onMovieLoaded, this
@movie.load() @movie.load()
@terminalView = new AsciiIo.TerminalView( @terminalView = new AsciiIo.TerminalView(
@ -12,7 +13,6 @@ class AsciiIo.PlayerView extends Backbone.View
@vt = new AsciiIo.VT(options.cols, options.lines, @terminalView) @vt = new AsciiIo.VT(options.cols, options.lines, @terminalView)
@createChildViews() @createChildViews()
@bindEvents()
createChildViews: -> createChildViews: ->
@$el.append(@terminalView.$el) @$el.append(@terminalView.$el)
@ -22,6 +22,17 @@ class AsciiIo.PlayerView extends Backbone.View
@hudView = new AsciiIo.HudView() @hudView = new AsciiIo.HudView()
@$el.append(@hudView.$el) @$el.append(@hudView.$el)
onMovieLoaded: (asciicast) ->
@terminalView.hideLoadingIndicator()
@hudView.setDuration(asciicast.get('duration'))
@bindEvents()
if @options.autoPlay
@movie.play()
else
@terminalView.showToggleOverlay()
bindEvents: -> bindEvents: ->
@terminalView.on 'terminal-click', => @terminalView.on 'terminal-click', =>
@movie.togglePlay() @movie.togglePlay()
@ -32,12 +43,6 @@ class AsciiIo.PlayerView extends Backbone.View
@hudView.on 'hud-seek-click', (percent) => @hudView.on 'hud-seek-click', (percent) =>
@movie.seek(percent) @movie.seek(percent)
@movie.on 'movie-loaded', (asciicast) =>
@terminalView.hideLoadingIndicator()
@hudView.setDuration(asciicast.get('duration'))
unless @options.autoPlay
@terminalView.showToggleOverlay()
@movie.on 'movie-playback-paused', => @movie.on 'movie-playback-paused', =>
@hudView.onPause() @hudView.onPause()