From 129485956073bbca11f0198e9342257b714ba222 Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 12:37:02 +0200 Subject: [PATCH 1/7] fix lint script calls --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8369c87..b644561 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "dist": "yarn lint && yarn build && yarn release", "start": "webpack-dev-server", "release": "webpack", - "lint": "eslint index.js" + "lint": "eslint src index.js", + "lint:fix": "eslint src index.js --fix" }, "author": "Clappr team", "license": "BSD-3-Clause", From 0bf13deb4e0dea10293ae1fe3cdf8027785e6c55 Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 12:37:29 +0200 Subject: [PATCH 2/7] add isAudioOnly implementation to plugin --- src/clappr-dash-shaka-playback.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index 6b66305..2315337 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -124,6 +124,15 @@ class DashShakaPlayback extends HTML5Video { } } + /** + * Determine if the playback does not contain video/has video but video should be ignored. + * @property isAudioOnly + * @type Boolean + */ + get isAudioOnly() { + return this.isReady ? this._player.isAudioOnly() : false + } + get textTracks () { return this.isReady && this._player.getTextTracks() } From 51979292d2032cfddad5e6ea704a61a830cfceb0 Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 12:40:45 +0200 Subject: [PATCH 3/7] When there is only one track per language, there are no more "variant" type tracks for audio payload. We just get a list of unique languages. Therefore we need to extend the plugin API to be able to select languages that are not "variant". - add selectLanguage method with a "role" parameter. this can allow to choose between "variants" of one language (if there are any, they can be find in the audioTracks property) - improve selectTrack (use switch-case) --- src/clappr-dash-shaka-playback.js | 37 ++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index 2315337..e1a9f84 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -149,21 +149,32 @@ class DashShakaPlayback extends HTML5Video { return (this.isReady && this._player.isLive() ? 'live' : 'vod') || '' } - selectTrack (track) { - if (track.type === 'text') { - this._player.selectTextTrack(track) - } else if (track.type === 'variant') { - this._player.selectVariantTrack(track) - if (track.mimeType.startsWith('video/')) { - // we trigger the adaptation event here - // because Shaka doesn't trigger its event on "manual" selection. - this._onAdaptation() - } - } else { - throw new Error('Unhandled track type:', track.type); + selectTrack (track, clearBuffer) { + switch(track.type) { + case 'text': + this._player.selectTextTrack(track) + break + case 'variant': + this._player.selectVariantTrack(track, clearBuffer) + if (track.mimeType.startsWith('video/')) { + // we trigger the adaptation event here + // because Shaka doesn't trigger its event on "manual" selection. + this._onAdaptation() + } + break + default: + throw new Error('Unhandled track type:', track.type) } } + selectLanguage(language, role) { + this._player.selectAudioLanguage(language, role) + } + + get audioLanguages() { + return this._player.getAudioLanguages() + } + /** * @override */ @@ -290,7 +301,7 @@ class DashShakaPlayback extends HTML5Video { } _loaded () { - this._onShakaReady(); + this._onShakaReady() this._startToSendStats() this._fillLevels() this._checkForClosedCaptions() From 0703004eabc01146347baf9dc78c162d780392cc Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 12:40:53 +0200 Subject: [PATCH 4/7] add .editorconfig file --- .editorconfig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b01d022 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,21 @@ +# editorconfig.org + +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true + +indent_style = space +indent_size = 2 + +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[{package.json}] +indent_style = space +indent_size = 2 From ca9d2d44ae5f20ed5dac74cf13820668ee94ba81 Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 14:02:25 +0200 Subject: [PATCH 5/7] allow to manage preferred/active audio language correctly --- src/clappr-dash-shaka-playback.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index e1a9f84..f70e230 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -59,6 +59,7 @@ class DashShakaPlayback extends HTML5Video { this._levels = [] this._pendingAdaptationEvent = false this._isShakaReadyState = false + this._activeAudioLanguage = null; options.autoPlay && this.play() } @@ -150,10 +151,13 @@ class DashShakaPlayback extends HTML5Video { } selectTrack (track, clearBuffer) { + if (this.isReady) { + return false + } switch(track.type) { case 'text': this._player.selectTextTrack(track) - break + return true case 'variant': this._player.selectVariantTrack(track, clearBuffer) if (track.mimeType.startsWith('video/')) { @@ -161,18 +165,27 @@ class DashShakaPlayback extends HTML5Video { // because Shaka doesn't trigger its event on "manual" selection. this._onAdaptation() } - break + return true default: throw new Error('Unhandled track type:', track.type) } } selectLanguage(language, role) { - this._player.selectAudioLanguage(language, role) + if (this.isReady) { + this._activeAudioLanguage = language + this._player.selectAudioLanguage(language, role) + return true + } + return false } get audioLanguages() { - return this._player.getAudioLanguages() + return this.isReady && this._player.getAudioLanguages() + } + + get activeAudioLanguage() { + return this._activeAudioLanguage || this.audioLanguages[0] || null } /** @@ -281,6 +294,9 @@ class DashShakaPlayback extends HTML5Video { this._options.shakaConfiguration && this._player.configure(this._options.shakaConfiguration) this._options.shakaOnBeforeLoad && this._options.shakaOnBeforeLoad(this._player) + const preferredAudioLanguage = this._player.getConfiguration().preferredAudioLanguage + this._activeAudioLanguage = preferredAudioLanguage.length ? preferredAudioLanguagee : null + let playerLoaded = this._player.load(this._options.src) playerLoaded.then(() => this._loaded()) .catch((e) => this._setupError(e)) From a10001a4e9e1d0654eadd43259c1dd7daf521b71 Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 14:04:23 +0200 Subject: [PATCH 6/7] fix lint / typo --- src/clappr-dash-shaka-playback.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clappr-dash-shaka-playback.js b/src/clappr-dash-shaka-playback.js index f70e230..ce80158 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -59,7 +59,7 @@ class DashShakaPlayback extends HTML5Video { this._levels = [] this._pendingAdaptationEvent = false this._isShakaReadyState = false - this._activeAudioLanguage = null; + this._activeAudioLanguage = null options.autoPlay && this.play() } @@ -295,7 +295,7 @@ class DashShakaPlayback extends HTML5Video { this._options.shakaOnBeforeLoad && this._options.shakaOnBeforeLoad(this._player) const preferredAudioLanguage = this._player.getConfiguration().preferredAudioLanguage - this._activeAudioLanguage = preferredAudioLanguage.length ? preferredAudioLanguagee : null + this._activeAudioLanguage = preferredAudioLanguage.length ? preferredAudioLanguage : null let playerLoaded = this._player.load(this._options.src) playerLoaded.then(() => this._loaded()) From 726da91a0536e5cbb7cdf33a04910eaf49fdddf4 Mon Sep 17 00:00:00 2001 From: tchakabam Date: Thu, 21 Sep 2017 19:39:21 +0200 Subject: [PATCH 7/7] fix typo: we check in selectTrack for non-readiness of Shaka --- 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 ce80158..ca1d229 100644 --- a/src/clappr-dash-shaka-playback.js +++ b/src/clappr-dash-shaka-playback.js @@ -151,7 +151,7 @@ class DashShakaPlayback extends HTML5Video { } selectTrack (track, clearBuffer) { - if (this.isReady) { + if (!this.isReady) { return false } switch(track.type) {