Skip to content

Commit

Permalink
fix(FEC-7935): fix text selection logic (#55)
Browse files Browse the repository at this point in the history
use shaka setTextTrackVisibility to set text track display mode according to useNativeTextTrack config flag.
This change is part of kaltura/playkit-js-hls#65 and kaltura/playkit-js#263 - removing the overhead of handling in playkit-js is possible by using the Shaka APIs to set track visibility.
  • Loading branch information
OrenMe committed Jul 12, 2018
1 parent a9d41ca commit cefc2ce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
if (Utils.Object.hasPropertyPath(config, 'playback.options.html5.dash')) {
dashConfig = config.playback.options.html5.dash;
}
if (Utils.Object.hasPropertyPath(config, 'playback.useNativeTextTrack')) {
dashConfig.textTrackVisibile = Utils.Object.getPropertyPath(config, 'playback.useNativeTextTrack');
}
return new this(videoElement, source, dashConfig);
}

Expand Down Expand Up @@ -227,7 +230,6 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
this._shaka = new shaka.Player(this._videoElement);
this._maybeSetDrmConfig();
this._shaka.configure(this._config);
this._shaka.setTextTrackVisibility(false);
this._addBindings();
}

Expand Down Expand Up @@ -493,6 +495,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
*/
selectTextTrack(textTrack: TextTrack): void {
if (this._shaka && (textTrack instanceof TextTrack) && !textTrack.active && (textTrack.kind === 'subtitles' || textTrack.kind === 'captions')) {
this._shaka.setTextTrackVisibility(this._config.textTrackVisibile);
this._shaka.selectTextLanguage(textTrack.language);
this._onTrackChanged(textTrack);
}
Expand Down
60 changes: 47 additions & 13 deletions test/src/dash-adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ describe('DashAdapter: load', () => {
dashInstance = DashAdapter.createAdapter(video, vodSource, config);
dashInstance.load().then(() => {
done();
}).catch(e => {
done(e)
});
});

Expand Down Expand Up @@ -225,6 +227,8 @@ describe('DashAdapter: destroy', () => {
dashInstance._buffering.should.be.false;
done();
});
}).catch(e => {
done(e);
});
});
});
Expand Down Expand Up @@ -307,10 +311,15 @@ describe('DashAdapter: selectVideoTrack', () => {

it('should select a new video track', (done) => {
let inactiveTrack;
let error;
let onVideoTrackChanged = (event) => {
dashInstance.removeEventListener('videotrackchanged', onVideoTrackChanged);
event.payload.selectedVideoTrack.id.should.be.equal(inactiveTrack.id);
done();
try {
event.payload.selectedVideoTrack.id.should.be.equal(inactiveTrack.id);
done(error);
} catch (e) {
done(e);
}
};
dashInstance.load().then(() => {
dashInstance.addEventListener('videotrackchanged', onVideoTrackChanged);
Expand All @@ -321,7 +330,11 @@ describe('DashAdapter: selectVideoTrack', () => {
let activeTrack = dashInstance._getVideoTracks().filter((track) => {
return track.active;
})[0];
activeTrack.id.should.be.equal(inactiveTrack.id);
try {
activeTrack.id.should.be.equal(inactiveTrack.id);
} catch (e) {
error = e;
}
});
});

Expand Down Expand Up @@ -453,8 +466,12 @@ describe('DashAdapter: selectAudioTrack', () => {
return track.active;
})[0].id);
setTimeout(() => {
eventIsFired.should.be.false;
done();
try {
eventIsFired.should.be.false;
done();
} catch (e) {
done(e);
}
}, 1000)
});
});
Expand Down Expand Up @@ -551,8 +568,12 @@ describe('DashAdapter: selectTextTrack', () => {
return track.active;
})[0].language);
setTimeout(() => {
eventCounter.should.equals(1);
done();
try {
eventCounter.should.equals(1);
done();
} catch (e) {
done(e);
}
}, 1000)
});
});
Expand Down Expand Up @@ -638,23 +659,30 @@ describe('DashAdapter: enableAdaptiveBitrate', () => {
TestUtils.removeVideoElementsFromTestPage();
});

it('should enable ABR', () => {
it('should enable ABR', (done) => {
dashInstance.load().then(() => {
dashInstance._shaka.getConfiguration().abr.enabled.should.be.false;
dashInstance.enableAdaptiveBitrate();
dashInstance._shaka.getConfiguration().abr.enabled.should.be.true;
dashInstance.isAdaptiveBitrateEnabled().should.be.true;
done();
}).catch((e) => {
done(e)
});
});

it('should fire abr mode changed event', (done) => {
let mode = 'manual';
let counter = 0;
dashInstance.addEventListener('abrmodechanged', (event) => {
event.payload.mode.should.equal(mode);
counter++;
if (counter === 3) {
done();
try {
event.payload.mode.should.equal(mode);
counter++;
if (counter === 3) {
done();
}
} catch (e) {
done(e);
}
});
dashInstance.load().then(() => {
Expand Down Expand Up @@ -693,6 +721,8 @@ describe('DashAdapter: isLive', () => {
dashInstance.load().then(() => {
dashInstance.isLive().should.be.false;
done();
}).catch(e => {
done(e);
});
});

Expand Down Expand Up @@ -769,10 +799,12 @@ describe('DashAdapter: seekToLiveEdge', () => {
dashInstance = DashAdapter.createAdapter(video, liveSource, config);
dashInstance.load().then(() => {
video.currentTime = dashInstance._shaka.seekRange().start;
((dashInstance._shaka.seekRange().end - video.currentTime) >= 30).should.be.true;
((dashInstance._shaka.seekRange().end - video.currentTime) >= 20).should.be.true;
dashInstance.seekToLiveEdge();
((dashInstance._shaka.seekRange().end - video.currentTime) <= 1).should.be.true;
done();
}).catch((e) => {
done(e)
});
});

Expand All @@ -784,6 +816,8 @@ describe('DashAdapter: seekToLiveEdge', () => {
dashInstance.seekToLiveEdge();
((dashInstance._shaka.seekRange().end - video.currentTime) < 1).should.be.true;
done();
}).catch((e) => {
done(e)
});
});
});
Expand Down

0 comments on commit cefc2ce

Please sign in to comment.