timing-object icon indicating copy to clipboard operation
timing-object copied to clipboard

Differentiating between self call and external call

Open infojunkie opened this issue 6 months ago • 4 comments

I am working on a media player that uses a TimingObject using your implementation here, and I have a question about the expected programming model. Consider the following cases:

  • My player exposes its internal this._timingObject to let UI clients be notified of playback changes, and possibly control the playback.

  • The UI client calls the exposed function player.play() to start playback.

  • When the player starts playing, it calls this._timingObject.update({ velocity: 1 }); to alert any listeners that playback has started.

  • The UI client calls this._timingObject.update({ velocity: 2 }); to change the playback speed. I would like the player to set up an event listener on this._timingObject to respond to the velocity update.

But how can the player differentiate between internal change events (as caused by play() invocations) versus external changes (such as update({ velocity }) ? Is the TimingObject programming model expecting both scenarios, or is it implied that ALL player changes should be done via TimingObject.update() calls?

PS. I've tried wrapping the player's calls to this._timingObject.update() within a function that unregisters its own change listener before the call, and re-registers it after the promise resolves, but it would seem that the change event is generated outside of the TimingObject.update() calls completely.

infojunkie avatar Jul 29 '24 01:07 infojunkie