From 3074d19c7302548b4eb4655d0fd3fb17f596b823 Mon Sep 17 00:00:00 2001 From: Oren Me Date: Thu, 12 Jul 2018 12:15:01 +0300 Subject: [PATCH] fix(FEC-7935): fix text selection logic with hlsjs (#65) this is basically the same as before, but hls.js run different code paths when we use it's API for selecting text track. Before this change we used to set the showing/hidden mode attribute of the text track in playkit-js html5 engine. we now set this in HLS.JS which internally does the same but also it manages internal state for this and so it's better to use its API and not access the textTrack.mode directly. This fix depends on a fix in kaltura/playkit-js#263 --- src/hls-adapter.js | 21 ++++++--------------- test/src/hls-adapter.spec.js | 23 ----------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/src/hls-adapter.js b/src/hls-adapter.js index 08268439..0f7c2e21 100644 --- a/src/hls-adapter.js +++ b/src/hls-adapter.js @@ -149,6 +149,9 @@ export default class HlsAdapter extends BaseMediaSourceAdapter { adapterConfig.hlsConfig.startPosition = config.playback.startTime; } } + if (Utils.Object.hasPropertyPath(config, 'playback.useNativeTextTrack')) { + adapterConfig.subtitleDisplay = Utils.Object.getPropertyPath(config, 'playback.useNativeTextTrack'); + } return new this(videoElement, source, adapterConfig); } @@ -202,6 +205,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter { this._config.hlsConfig['pLoader'] = pLoader; } this._hls = new Hlsjs(this._config.hlsConfig); + this._hls.subtitleDisplay = this._config.subtitleDisplay; this._addBindings(); } @@ -479,8 +483,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter { */ selectTextTrack(textTrack: TextTrack): void { if (textTrack instanceof TextTrack && !textTrack.active && this._videoElement.textTracks) { - this._disableAllTextTracks(); - this._videoElement.textTracks[textTrack.index].mode = 'hidden'; + this._hls.subtitleTrack = textTrack.index; HlsAdapter._logger.debug('Text track changed', textTrack); this._onTrackChanged(textTrack); } @@ -492,7 +495,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter { * @public */ hideTextTrack(): void { - this._disableAllTextTracks(); + this._hls.subtitleTrack = -1; } /** @@ -644,18 +647,6 @@ export default class HlsAdapter extends BaseMediaSourceAdapter { } } - /** - * Disables all the video tag text tracks. - * @returns {void} - * @private - */ - _disableAllTextTracks() { - let vidTextTracks = this._videoElement.textTracks; - for (let i = 0; i < vidTextTracks.length; i++) { - vidTextTracks[i].mode = 'disabled'; - } - } - /** * Handles hls errors. * @param {any} data - The event data object. diff --git a/test/src/hls-adapter.spec.js b/test/src/hls-adapter.spec.js index 284bdf32..afff96d5 100644 --- a/test/src/hls-adapter.spec.js +++ b/test/src/hls-adapter.spec.js @@ -210,29 +210,6 @@ describe('HlsAdapter Instance - Unit', function () { JSON.parse(JSON.stringify(tracks)).should.deep.equal(allTracks); }); - it('should disable all text tracks', function () { - hlsAdapterInstance._videoElement = { - textTracks: hls_tracks.subtitles, - removeEventListener: () => {} - }; - hlsAdapterInstance._disableAllTextTracks(); - for (let i = 0; i < hlsAdapterInstance._videoElement.textTracks.length; i++) { - hlsAdapterInstance._videoElement.textTracks[i].mode.should.equal('disabled'); - } - }); - - it('should hide the active text track', function () { - hlsAdapterInstance._videoElement = { - textTracks: hls_tracks.subtitles, - removeEventListener: () => {} - }; - hlsAdapterInstance._videoElement.textTracks[0].mode = 'showing'; - hlsAdapterInstance.hideTextTrack(); - for (let i = 0; i < hlsAdapterInstance._videoElement.textTracks.length; i++) { - hlsAdapterInstance._videoElement.textTracks[i].mode.should.equal('disabled'); - } - }); - it('should enable adaptive bitrate', function () { hlsAdapterInstance._hls = { on: function () {