From f02623a67fb27bbb26b4da5ee0d49eb1a8e6beb0 Mon Sep 17 00:00:00 2001 From: Jhonatan Gomes Date: Thu, 8 Oct 2020 10:55:33 -0300 Subject: [PATCH 1/6] add static getter to shaka player lib --- src/clappr-dash-shaka-playback.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index 2d53266..eb51f1b 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -11,6 +11,8 @@ class DashShakaPlayback extends HTML5Video { } } + static get shakaPlayer() { return shaka } + static canPlay (resource, mimeType = '') { shaka.polyfill.installAll() let browserSupported = shaka.Player.isBrowserSupported() From cd64efe44064c723de4a9bb77b20947808ef64c8 Mon Sep 17 00:00:00 2001 From: Jhonatan Gomes Date: Thu, 8 Oct 2020 11:00:09 -0300 Subject: [PATCH 2/6] trigger buffering/bufferfull events only from shaka The _handleBufferingEvents should be override to avoid duplicated buffering/bufferfull events. --- src/clappr-dash-shaka-playback.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index eb51f1b..c29415a 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -374,9 +374,13 @@ class DashShakaPlayback extends HTML5Video { this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name) } + // skipping HTML5 `_handleBufferingEvents` in favor of shaka buffering events + _handleBufferingEvents() {} + _onBuffering (e) { if (this._stopped) return - let event = e.buffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL + this._isBuffering = e.buffering + let event = this._isBuffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL this.trigger(event) } From 5a3be2b0af6e799d30f99088daeb3f2f10419ea1 Mon Sep 17 00:00:00 2001 From: Jhonatan Gomes Date: Thu, 8 Oct 2020 11:01:20 -0300 Subject: [PATCH 3/6] fix trigger of playing event --- src/clappr-dash-shaka-playback.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index c29415a..9cd3903 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -143,6 +143,15 @@ class DashShakaPlayback extends HTML5Video { this._startTimeUpdateTimer() } + _onPlaying() { + /* + The `_onPlaying` should not be called while buffering: https://github.com/google/shaka-player/issues/2230 + It will be executed on bufferfull. + */ + if (this._isBuffering) return + return super._onPlaying() + } + _startTimeUpdateTimer() { this._stopTimeUpdateTimer() this._timeUpdateTimer = setInterval(() => { @@ -382,6 +391,7 @@ class DashShakaPlayback extends HTML5Video { this._isBuffering = e.buffering let event = this._isBuffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL this.trigger(event) + if (!this._isBuffering) this._onPlaying() } _loaded () { From a62032025498321b8428e3269af48a89b1602d54 Mon Sep 17 00:00:00 2001 From: Jhonatan Gomes Date: Thu, 8 Oct 2020 17:36:18 -0300 Subject: [PATCH 4/6] fix trigger of seeked event --- src/clappr-dash-shaka-playback.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index 9cd3903..d5269eb 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -152,6 +152,22 @@ class DashShakaPlayback extends HTML5Video { return super._onPlaying() } + _onSeeking() { + this._isSeeking = true + return super._onSeeking() + } + + _onSeeked() { + /* + The `_onSeeked` should not be called while buffering. + It will be executed on bufferfull. + */ + if (this._isBuffering) return + + this._isSeeking = false + return super._onSeeked() + } + _startTimeUpdateTimer() { this._stopTimeUpdateTimer() this._timeUpdateTimer = setInterval(() => { @@ -391,6 +407,7 @@ class DashShakaPlayback extends HTML5Video { this._isBuffering = e.buffering let event = this._isBuffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL this.trigger(event) + if (!this._isBuffering && this._isSeeking) this._onSeeked() if (!this._isBuffering) this._onPlaying() } From d3d783c98d6cf5bffcda874dbf302d7caa5ad949 Mon Sep 17 00:00:00 2001 From: Jhonatan Gomes Date: Fri, 9 Oct 2020 16:01:35 -0300 Subject: [PATCH 5/6] avoid triggering playing when paused --- src/clappr-dash-shaka-playback.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index d5269eb..d3170d6 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -408,7 +408,7 @@ class DashShakaPlayback extends HTML5Video { let event = this._isBuffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL this.trigger(event) if (!this._isBuffering && this._isSeeking) this._onSeeked() - if (!this._isBuffering) this._onPlaying() + if (!this._isBuffering && this.isPlaying()) this._onPlaying() } _loaded () { From 97562baadcaa521b4fb4937c5d43bbde69f47f1d Mon Sep 17 00:00:00 2001 From: Jhonatan Gomes Date: Fri, 9 Oct 2020 16:09:55 -0300 Subject: [PATCH 6/6] split buffering/bufferfull handlers --- src/clappr-dash-shaka-playback.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index d3170d6..0e0962b 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -377,7 +377,7 @@ class DashShakaPlayback extends HTML5Video { let player = new shaka.Player(this.el) player.addEventListener('error', this._onError.bind(this)) player.addEventListener('adaptation', this._onAdaptation.bind(this)) - player.addEventListener('buffering', this._onBuffering.bind(this)) + player.addEventListener('buffering', this._handleShakaBufferingEvents.bind(this)) return player } @@ -402,13 +402,21 @@ class DashShakaPlayback extends HTML5Video { // skipping HTML5 `_handleBufferingEvents` in favor of shaka buffering events _handleBufferingEvents() {} - _onBuffering (e) { + _handleShakaBufferingEvents(e) { if (this._stopped) return + this._isBuffering = e.buffering - let event = this._isBuffering ? Events.PLAYBACK_BUFFERING : Events.PLAYBACK_BUFFERFULL - this.trigger(event) - if (!this._isBuffering && this._isSeeking) this._onSeeked() - if (!this._isBuffering && this.isPlaying()) this._onPlaying() + this._isBuffering ? this._onBuffering() : this._onBufferfull() + } + + _onBuffering () { + this.trigger(Events.PLAYBACK_BUFFERING) + } + + _onBufferfull() { + this.trigger(Events.PLAYBACK_BUFFERFULL) + if (this._isSeeking) this._onSeeked() + if (this.isPlaying()) this._onPlaying() } _loaded () {