Skip to content

Commit

Permalink
feat(FEC-13462): handle the playback rate after medialoaded event (#733)
Browse files Browse the repository at this point in the history
### Description of the Changes

- handle the `playbackRate` after `medialoaded` event, in order to overcome race condition, where the playbackRate is being overwritten; the engine is re-initializing the playbackRate after the media is loaded.

Solves FEC-13462
  • Loading branch information
lianbenjamin authored Nov 21, 2023
1 parent 59652d2 commit 16a4ffa
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,8 @@ export default class Player extends FakeEventTarget {
this._readyPromise = new Promise((resolve, reject) => {
this._eventManager.listenOnce(this, CustomEventType.TRACKS_CHANGED, () => {
this.dispatchEvent(new FakeEvent(CustomEventType.MEDIA_LOADED));
// handle playback rate after media loaded, to avoid race condition, so it won't be overwritten
this._handlePlaybackRate();
resolve();
});
this._eventManager.listen(this, Html5EventType.ERROR, (event: FakeEvent) => {
Expand All @@ -1843,6 +1845,19 @@ export default class Player extends FakeEventTarget {
});
}
/**
* Handles the playback rate.
* @private
* @returns {void}
*/
_handlePlaybackRate(): void {
if (typeof this._playbackAttributesState.rate === 'number') {
this.playbackRate = this._playbackAttributesState.rate;
} else if (typeof this._config.playback.playbackRate === 'number') {
this.playbackRate = this._config.playback.playbackRate;
}
}
/**
* Selects an engine to play a source according to a given stream priority.
* @return {boolean} - Whether a proper engine was found to play the given sources
Expand Down Expand Up @@ -2080,11 +2095,6 @@ export default class Player extends FakeEventTarget {
if (typeof this._config.playback.crossOrigin === 'string') {
this.crossOrigin = this._config.playback.crossOrigin;
}
if (typeof this._playbackAttributesState.rate === 'number') {
this.playbackRate = this._playbackAttributesState.rate;
} else if (typeof this._config.playback.playbackRate === 'number') {
this.playbackRate = this._config.playback.playbackRate;
}
if (Array.isArray(this._config.playback.playbackRates)) {
const validPlaybackRates = this._config.playback.playbackRates
.filter((number, index, self) => number > 0 && number <= 16 && self.indexOf(number) === index)
Expand Down

0 comments on commit 16a4ffa

Please sign in to comment.