Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-8808): handle preload metadata #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/hls-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
* @private
*/
_onVideoErrorCallback: ?Function;
/**
* Flag to mark that the first 'play' event of the video tag was sent.
* @member {?Function} - _onVideoErrorCallback
* @type {?Function}
* @private
*/
_firstPlayEvent: boolean;

/**
* Reference to _onRecoveredCallback function
Expand Down Expand Up @@ -253,6 +260,15 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._onAddTrack = this._onAddTrack.bind(this);
this._videoElement.addEventListener('addtrack', this._onAddTrack);
this._videoElement.textTracks.onaddtrack = this._onAddTrack;
this._firstPlayEvent = true;
this._videoElement.addEventListener(EventType.PLAY, () => this._onPlay());
}

_onPlay() {
if (this._firstPlayEvent) {
this._hls.startLoad(this._startTime);
this._firstPlayEvent = false;
}
}

_onFpsDrop(data: Object): void {
Expand Down Expand Up @@ -315,6 +331,9 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
*/
_loadInternal() {
if (this._sourceObj && this._sourceObj.url) {
if (this._videoElement.preload === 'metadata') {
this._hls.config.autoStartLoad = false;
}
this._hls.loadSource(this._sourceObj.url);
this._hls.attachMedia(this._videoElement);
this._trigger(EventType.ABR_MODE_CHANGED, {mode: this.isAdaptiveBitrateEnabled() ? 'auto' : 'manual'});
Expand Down Expand Up @@ -668,7 +687,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
*/
_onManifestLoaded(): void {
HlsAdapter._logger.debug('The source has been loaded successfully');
if (!this._hls.config.autoStartLoad) {
if (!this._hls.config.autoStartLoad || this._videoElement.preload === 'auto') {
this._hls.startLoad(this._startTime);
}
this._playerTracks = this._parseTracks();
Expand Down