From 40f25dd23715c0e0f872886bb4292b17c91806ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Cunat?= Date: Fri, 12 Jun 2020 11:27:39 +0200 Subject: [PATCH] Fix regression with enableText (#3286) * Fix regression with enableText * [TextController] change unit test because subtitles are now disabled by default * enable text in captioning samples --- samples/captioning/caption_vtt.html | 1 + samples/captioning/multi-track-captions.html | 1 + samples/captioning/ttml-ebutt-sample.html | 1 + src/streaming/text/TextController.js | 25 ++++++++++++++++---- test/unit/streaming.text.TextController.js | 8 +++---- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/samples/captioning/caption_vtt.html b/samples/captioning/caption_vtt.html index 5744478985..a7539868d9 100644 --- a/samples/captioning/caption_vtt.html +++ b/samples/captioning/caption_vtt.html @@ -19,6 +19,7 @@ player = dashjs.MediaPlayer({}).create(); player.initialize(video, url, true); + player.setTextDefaultEnabled(true); } diff --git a/samples/captioning/multi-track-captions.html b/samples/captioning/multi-track-captions.html index af43391da7..ce33bb9412 100644 --- a/samples/captioning/multi-track-captions.html +++ b/samples/captioning/multi-track-captions.html @@ -28,6 +28,7 @@ player = dashjs.MediaPlayer().create(); player.initialize(videoElement, url, true); + player.setTextDefaultEnabled(true); player.setInitialMediaSettingsFor('fragmentedText', { lang: 'swe' }); diff --git a/samples/captioning/ttml-ebutt-sample.html b/samples/captioning/ttml-ebutt-sample.html index 388b4df1f5..f80f371699 100644 --- a/samples/captioning/ttml-ebutt-sample.html +++ b/samples/captioning/ttml-ebutt-sample.html @@ -33,6 +33,7 @@ player = dashjs.MediaPlayer().create(); player.initialize(videoElement, url, true); + player.setTextDefaultEnabled(true); player.attachTTMLRenderingDiv(TTMLRenderingDiv); controlbar = new ControlBar(player); // Checkout ControlBar.js for more info on how to target/add text tracks to UI controlbar.initialize(); diff --git a/src/streaming/text/TextController.js b/src/streaming/text/TextController.js index 162ceceeff..a894b00811 100644 --- a/src/streaming/text/TextController.js +++ b/src/streaming/text/TextController.js @@ -59,6 +59,8 @@ function TextController() { textDefaultEnabled, // this is used for default settings (each time a file is loaded, we check value of this settings ) allTracksAreDisabled, // this is used for one session (when a file has been loaded, we use this settings to enable/disable text) forceTextStreaming, + textTracksAdded, + disableTextBeforeTextTracksAdded, previousPeriodSelectedTrack; function setup() { @@ -67,6 +69,8 @@ function TextController() { lastEnabledIndex = -1; textDefaultEnabled = false; forceTextStreaming = false; + textTracksAdded = false; + disableTextBeforeTextTracksAdded = false; textTracks = TextTracks(context).getInstance(); vttParser = VTTParser(context).getInstance(); ttmlParser = TTMLParser(context).getInstance(); @@ -196,7 +200,7 @@ function TextController() { }); } - if (!textDefaultEnabled) { + if (!textDefaultEnabled || disableTextBeforeTextTracksAdded) { // disable text at startup this.setTextTrack(-1); } @@ -207,6 +211,7 @@ function TextController() { index: index, tracks: tracks }); + textTracksAdded = true; } function setTextDefaultEnabled(enable) { @@ -216,6 +221,8 @@ function TextController() { if (!textDefaultEnabled) { // disable text at startup this.setTextTrack(-1); + } else { + allTracksAreDisabled = false; } } @@ -225,18 +232,24 @@ function TextController() { function enableText(enable) { checkParameterType(enable,'boolean'); - + if (!textDefaultEnabled && enable) { + textDefaultEnabled = true; + } if (isTextEnabled() !== enable) { // change track selection if (enable) { - // apply last enabled tractk + // apply last enabled track this.setTextTrack(lastEnabledIndex); } if (!enable) { // keep last index and disable text track lastEnabledIndex = this.getCurrentTrackIdx(); - this.setTextTrack(-1); + if (!textTracksAdded) { + disableTextBeforeTextTracksAdded = true; + } else { + this.setTextTrack(-1); + } } } } @@ -331,7 +344,9 @@ function TextController() { } function resetInitialSettings() { - allTracksAreDisabled = false; + allTracksAreDisabled = true; + textTracksAdded = false; + disableTextBeforeTextTracksAdded = false; } function reset() { diff --git a/test/unit/streaming.text.TextController.js b/test/unit/streaming.text.TextController.js index cbe181485b..cffca5278e 100644 --- a/test/unit/streaming.text.TextController.js +++ b/test/unit/streaming.text.TextController.js @@ -148,13 +148,13 @@ describe('TextController', function () { it('should enable/disable text', function () { let textEnabled = textController.isTextEnabled(); - expect(textEnabled).to.equal(true); // jshint ignore:line - - textController.enableText(false); - expect(textController.isTextEnabled()).to.equal(false); // jshint ignore:line + expect(textEnabled).to.equal(false); // jshint ignore:line textController.enableText(true); expect(textController.isTextEnabled()).to.equal(true); // jshint ignore:line + + textController.enableText(false); + expect(textController.isTextEnabled()).to.equal(false); // jshint ignore:line }); });