Skip to main content

Media Playback

MediaPlayback allows us to control the execution of a media, such as a video. Under the hood MediaPlayback just synchronises start, pause and stop commands of a Clip with the corresponding commands of a media we want to control.

In order to create a custom MediaPlayback you need to extend the MediaPlayback Class of MotorCortex and you can overwrite the following methods:

  • play(milliseconds)
  • stop()
  • onProgress(fraction, milliseconds)

It might seem a bit oxymoron to provide both play/stop and onProgress method. The onProgress method runs only when the user seeks the Clip and not on normal execution.

When a Clip moves backward, MotorCortex reconciles playback with the media active at the destination and starts it at the corresponding offset. This reconciliation affects only the moved ClipCopy context. Media in other ClipCopy contexts is not stopped.

For Web Audio playback, play(milliseconds) returns false when the source is still loading or when the shared AudioContext is not running. The media channel uses that result to retry the start instead of recording a source as playing while it is silent. It retries pending starts every 50 milliseconds for up to 5 seconds. User-facing MotorCortex Player controls route starts through the player's play() method, which starts the context resume and Clip play in the same gesture task without awaiting the resume.