From 10b1f20c82831e07093ae361ccb28565acca2fe5 Mon Sep 17 00:00:00 2001 From: lianbenjamin <79077248+lianbenjamin@users.noreply.github.com> Date: Tue, 2 Mar 2021 18:40:58 +0200 Subject: [PATCH] fix(FEC-11052): audio stutters/lag in the newest V7 versions (#548) ### Description of the Changes Issue is that audio stutters when audio entry is playing and moving from entry's tab to other tabs and vice-versa on the browser. The stutter is caused by a fix for the following iOS bug - [FEC-10014](https://github.com/kaltura/playkit-js/pull/452). Solution is to limit the change was made in FEC-10014 to only iOS (and not for progressive). Solves [FEC-11052](https://kaltura.atlassian.net/browse/FEC-11052). --- .../media-source/adapters/native-adapter.js | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/engines/html5/media-source/adapters/native-adapter.js b/src/engines/html5/media-source/adapters/native-adapter.js index 99174d57d..e3daf1399 100644 --- a/src/engines/html5/media-source/adapters/native-adapter.js +++ b/src/engines/html5/media-source/adapters/native-adapter.js @@ -62,6 +62,13 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { * @static */ static _drmProtocol: ?Function = null; + /** + * The supported progressive mime types by the native adapter. + * @member {Array} _progressiveMimeTypes + * @static + * @private + */ + static _progressiveMimeTypes: Array = ['video/mp4', 'audio/mp3']; /** * The DRM handler playback. * @type {?FairPlayDrmHandler} @@ -286,7 +293,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { * @private */ _isProgressivePlayback(): boolean { - return this._sourceObj ? this._sourceObj.mimetype === 'video/mp4' : false; + return this._sourceObj ? NativeAdapter._progressiveMimeTypes.includes(this._sourceObj.mimetype.toLowerCase()) : false; } /** @@ -310,14 +317,16 @@ export default class NativeAdapter extends BaseMediaSourceAdapter { this._eventManager.listen(this._videoElement, Html5EventType.ABORT, () => this._clearHeartbeatTimeout()); this._eventManager.listen(this._videoElement, Html5EventType.SEEKED, () => this._syncCurrentTime()); // Sometimes when playing live in safari and switching between tabs the currentTime goes back with no seek events - this._eventManager.listen(window, 'focus', () => - setTimeout(() => { - // In IOS HLS, sometimes when coming back from lock screen/Idle mode, the stream will get stuck, and only a small seek nudge will fix it. - this._videoElement.currentTime = - this._videoElement.currentTime > NUDGE_SEEK_AFTER_FOCUS ? this._videoElement.currentTime - NUDGE_SEEK_AFTER_FOCUS : 0; - this._syncCurrentTime(); - }, BACK_TO_FOCUS_TIMEOUT) - ); + this._eventManager.listen(window, 'focus', () => { + if (!this._isProgressivePlayback()) { + setTimeout(() => { + // In IOS HLS, sometimes when coming back from lock screen/Idle mode, the stream will get stuck, and only a small seek nudge will fix it. + this._videoElement.currentTime = + this._videoElement.currentTime > NUDGE_SEEK_AFTER_FOCUS ? this._videoElement.currentTime - NUDGE_SEEK_AFTER_FOCUS : 0; + this._syncCurrentTime(); + }, BACK_TO_FOCUS_TIMEOUT); + } + }); if (this._isProgressivePlayback()) { this._setProgressiveSource(); }