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

fix(FEC-7564): trigger timeupdate in case of live when the playback is paused #191

Merged
merged 4 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/engines/html5/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class Html5 extends FakeEventTarget implements IEngine {
this._eventManager.listen(this._mediaSourceAdapter, CustomEventType.ABR_MODE_CHANGED, (event: FakeEvent) => this.dispatchEvent(event));
this._eventManager.listen(this._mediaSourceAdapter, CustomEventType.TEXT_CUE_CHANGED, (event: FakeEvent) => this.dispatchEvent(event));
this._eventManager.listen(this._mediaSourceAdapter, Html5EventType.ERROR, (event: FakeEvent) => this.dispatchEvent(event));
this._eventManager.listen(this._mediaSourceAdapter, Html5EventType.DURATION_CHANGE, (event: FakeEvent) => this.dispatchEvent(event));
this._eventManager.listen(this._mediaSourceAdapter, Html5EventType.TIME_UPDATE, (event: FakeEvent) => this.dispatchEvent(event));
this._eventManager.listen(this._mediaSourceAdapter, Html5EventType.PLAYING, (event: FakeEvent) => this.dispatchEvent(event));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/engines/html5/media-source/adapters/native-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
const liveEdge = this._getLiveEdge();
if (this._liveEdge !== liveEdge) {
this._liveEdge = liveEdge;
this._trigger(Html5EventType.DURATION_CHANGE, {});
this._videoElement.dispatchEvent(new window.Event(Html5EventType.DURATION_CHANGE));
}
}, 2000);
}
Expand All @@ -795,7 +795,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
* @public
*/
getStartTimeOfDvrWindow(): number {
if (this.isLive()) {
if (this.isLive() && this._videoElement.seekable.length) {
return this._videoElement.seekable.start(0);
} else {
return 0;
Expand Down
19 changes: 17 additions & 2 deletions src/engines/html5/media-source/base-media-source-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I
this._videoElement = videoElement;
this._sourceObj = source;
this._config = config;
this._handleLiveTimeUpdate();
}

/**
Expand Down Expand Up @@ -105,10 +106,10 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I
/**
* Dispatch an adapter event forward.
* @param {string} name - The name of the event.
* @param {Object} payload - The event payload.
* @param {?Object} payload - The event payload.
* @returns {void}
*/
_trigger(name: string, payload: Object): void {
_trigger(name: string, payload?: Object): void {
this.dispatchEvent(new FakeEvent(name, payload));
}

Expand Down Expand Up @@ -158,6 +159,20 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I
return BaseMediaSourceAdapter._throwNotImplementedError('isLive');
}

/**
* Handling live time update (as is not triggered when video is paused, but the current time changed)
* @function _handleLiveTimeUpdate
* @returns {void}
* @private
*/
_handleLiveTimeUpdate(): void {
this._videoElement.addEventListener(Html5EventType.DURATION_CHANGE, () => {
if (this.isLive() && this._videoElement.paused) {
this._trigger(Html5EventType.TIME_UPDATE);
}
});
}

get src(): string {
return BaseMediaSourceAdapter._throwNotImplementedError('get src');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,35 @@ describe('NativeAdapter: _handleLiveDurationChange', () => {
it('should trigger durationchange for live', (done) => {
nativeInstance = NativeAdapter.createAdapter(video, sourcesConfig.Live.hls[0], {sources: {}});
nativeInstance.load().then(() => {
nativeInstance.addEventListener('durationchange', () => {
nativeInstance._videoElement.addEventListener('durationchange', () => {
done();
});
}).catch(() => {
done();
});
});
});

describe('NativeAdapter: _handleLiveTimeUpdate', () => {
let video, nativeInstance;

beforeEach(() => {
video = document.createElement("video");
});

afterEach(() => {
nativeInstance.destroy();
nativeInstance = null;
});

after(() => {
removeVideoElementsFromTestPage();
});

it('should trigger timeupdate for live when paused', (done) => {
nativeInstance = NativeAdapter.createAdapter(video, sourcesConfig.Live.hls[0], {sources: {}});
nativeInstance.load().then(() => {
nativeInstance.addEventListener('timeupdate', () => {
done();
});
}).catch(() => {
Expand Down