Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Capture if the captions are displaying (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
commuterjoy authored Feb 6, 2017
1 parent 06f6a66 commit e5e5bf0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function eventListener(video, ev) {

fireEvent(ev.type, video, {
progress: video.getProgress(),
duration: video.getDuration()
duration: video.getDuration(),
textTrackMode: video.getTrackMode()
});
}

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e5e5bf0

Please sign in to comment.