Skip to content

Commit

Permalink
fix(FEC-11035): playback error dispatch from player instead of from e…
Browse files Browse the repository at this point in the history
…ngine (#545)

Issue: engine doesn't expose an error for playback error, it dispatched from the player instead - the engine decorator can't ignore the playback error.
Solution: change the dispatch from the player to the engine to make sure the playback error could reject on the engine decorator.
tests failed for scenario _nativeTextTracksMap has index 0 and 2(metadata between) so for raise an error when it gets to i = 1 that doesn't exist.
  • Loading branch information
Yuvalke authored Mar 11, 2021
1 parent 35b83ad commit 848bf1b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
28 changes: 16 additions & 12 deletions src/engines/html5/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,22 @@ export default class Html5 extends FakeEventTarget implements IEngine {
*/
load(startTime: ?number): Promise<Object> {
this._el.load();
return this._canLoadMediaSourceAdapterPromise
.then(() => {
if (this._mediaSourceAdapter) {
return this._mediaSourceAdapter.load(startTime).catch(error => {
return Promise.reject(error);
});
}
return Promise.resolve({});
})
.catch(error => {
return Promise.reject(error);
});
return new Promise((resolve, reject) => {
this._canLoadMediaSourceAdapterPromise
.then(() => {
if (this._mediaSourceAdapter) {
this._mediaSourceAdapter
.load(startTime)
.then(tracks => resolve(tracks))
.catch(error => reject(error));
} else {
resolve({});
}
})
.catch(error => {
reject(error);
});
}).catch(error => this.dispatchEvent(new FakeEvent(Html5EventType.ERROR, error)));
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/engines/html5/media-source/adapters/native-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
const pkTextTracks = this._getPKTextTracks();
const pkOffTrack = pkTextTracks.find(track => track.language === 'off');
const getActiveVidTextTrackIndex = () => {
for (let i = 0; i < this._nativeTextTracksMap.length; i++) {
const textTrack = this._nativeTextTracksMap[i];
if (this._getDisplayTextTrackModeString() === textTrack.mode) {
return i;
}
}
return -1;
return this._nativeTextTracksMap.findIndex(textTrack => textTrack && this._getDisplayTextTrackModeString() === textTrack.mode);
};
NativeAdapter._logger.debug('Video element text track change');
const vidIndex = getActiveVidTextTrackIndex();
Expand Down
22 changes: 8 additions & 14 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2003,10 +2003,8 @@ export default class Player extends FakeEventTarget {
}
this._updateTracks(data.tracks);
this.dispatchEvent(new FakeEvent(CustomEventType.TRACKS_CHANGED, {tracks: this._tracks}));
resetFlags();
})
.catch(error => {
this.dispatchEvent(new FakeEvent(Html5EventType.ERROR, error));
.finally(() => {
resetFlags();
});
}
Expand Down Expand Up @@ -2034,17 +2032,13 @@ export default class Player extends FakeEventTarget {
this._load();
this._shouldLoadAfterAttach = false;
}
this.ready()
.then(() => {
const liveOrDvrOutOfWindow = this.isLive() && (!this.isDvr() || (typeof this.currentTime === 'number' && this.currentTime < 0));
if (!this._firstPlay && liveOrDvrOutOfWindow) {
this.seekToLiveEdge();
}
this._engine.play();
})
.catch(error => {
this.dispatchEvent(new FakeEvent(Html5EventType.ERROR, error));
});
this.ready().then(() => {
const liveOrDvrOutOfWindow = this.isLive() && (!this.isDvr() || (typeof this.currentTime === 'number' && this.currentTime < 0));
if (!this._firstPlay && liveOrDvrOutOfWindow) {
this.seekToLiveEdge();
}
this._engine.play();
});
}

/**
Expand Down

0 comments on commit 848bf1b

Please sign in to comment.