# class Player

new Player(totalTime) // -> Player
// -- or --
Player.create(totalTime) // -> Player

A time source that extends Observable that can be used to start, stop, seek, and loop the input time at will.

Extends Emitter and provides the following events: play, pause, togglePause, update, seek, end, destroy

Params

  • {String | Number} totalTime - The total time of this player

Examples

const player = new Player(tween.duration)

const subscription = player.pipe(tween)
  .subscribe(state => {
    // update display using state
  })

// elsewhere...
player.pause()
player.seek(2000) // seek to 2s
player.playTo(3000) // play until 3s
player.on('end', () => {
  player.seek(0) // go back to start once ended
})
// cleanup when finished
subscription.unsubscribe()
player.destroy()

# Player.progress

player.progress // -> Number
player.progress = p // set progress

Get or set the progress of the player. Progress is the percentage completion of the player.

# Player.time

player.time // -> Number
player.time = t // set time

Get or set the current time of the player in milliseconds.

# Player.paused

player.paused // -> Boolean
player.paused = isPaused // set paused state

Get or set the paused state.

# Player.playbackRate

player.playbackRate // -> Number
player.playbackRate = isPaused // set playback rate

Get or set the playback rate. A negative value will play backwards.

# Player.destroy()

player.destroy() // -> void

Clean up subscriptions and events.

Emits 'destroy' event.

# Player.loop()

player.loop() // -> this
player.loop(false) // -> this

Enable or disable looping of the player. If looping, the player begins again at time = 0 upon completion, but still emits the 'end' event.

Note: You may want Tween.loop() instead, depending on the situation.

# Player.pause()

player.pause() // -> this

Pause.

# Player.play()

player.play() // -> this

Play.

# Player.playTo()

player.playTo(time) // -> this

Play up until specified time, then pause.

Note: If time < player.time then it will change the playbackRate to be -1 and play backwards to specified time.

Params

  • {String | Number} time

# Player.seek()

player.seek(time) // -> this

Seek to specified time in milliseconds.

Emits the 'seek' event.

Params

  • {Number} time - Time in milliseconds

# Player.togglePause()

player.togglePause() // -> this
player.togglePause(toggle) // -> this

Set or toggle paused state.

Params

  • {Boolean} toggle - If specified, sets the pause state. Otherwise, toggles or untoggles pause.
Last Updated: 9/14/2021, 5:49:55 PM