From e5e5bf03f5b8b750ad44d9688d5d3859ca110f23 Mon Sep 17 00:00:00 2001 From: Matt Chadburn Date: Mon, 6 Feb 2017 13:23:42 +0000 Subject: [PATCH] Capture if the captions are displaying (#88) --- src/js/video.js | 7 ++++++- test/video.test.js | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/js/video.js b/src/js/video.js index 21689df..bae5125 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -27,7 +27,8 @@ function eventListener(video, ev) { fireEvent(ev.type, video, { progress: video.getProgress(), - duration: video.getDuration() + duration: video.getDuration(), + textTrackMode: video.getTrackMode() }); } @@ -344,6 +345,10 @@ class Video { return this.videoEl.duration ? parseInt(this.videoEl.duration, 10) : 0; } + getTrackMode() { + return this.videoEl.textTracks && this.videoEl.textTracks[0] ? this.videoEl.textTracks[0].mode : undefined; + } + getAmountWatched(decimalPoints) { const secondsWatched = this.amountWatched / 1000; return decimalPoints !== undefined ? +(secondsWatched).toFixed(decimalPoints) : secondsWatched; diff --git a/test/video.test.js b/test/video.test.js index d1f975a..4057292 100644 --- a/test/video.test.js +++ b/test/video.test.js @@ -487,6 +487,26 @@ describe('Video', () => { }); + describe('#getTrackMode', () => { + + it('should return the state of the video text track', () => { + const video = new Video(containerEl, { captionsUrl: 'http://localhost/a.vtt' }); + video.addVideo(); + setTimeout(() => { + video.getTrackMode().should.equal('disabled'); + }, 100); + }); + + it('should return undefined if the video has no captions', () => { + const video = new Video(containerEl, {}); + video.addVideo(); + setTimeout(() => { + video.getTrackMode().should.equal(undefined); + }, 100); + }); + + }); + describe('#getDuration', () => { let video;