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

Commit

Permalink
Video duration is an integer
Browse files Browse the repository at this point in the history
By default the duration is reported as `ss.mm`, often to ~12 decimal
places, which makes grouping at reporting stage less useful.
  • Loading branch information
commuterjoy committed Jan 5, 2017
1 parent 8651a08 commit d7b46f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function eventListener(video, ev) {
category: 'video',
contentId: video.opts.id,
progress: video.getProgress(),
duration: video.videoEl.duration
duration: video.getDuration()
},
bubbles: true
});
Expand Down Expand Up @@ -289,6 +289,10 @@ class Video {
return this.videoEl.duration ? parseInt(100 * this.videoEl.currentTime / this.videoEl.duration, 10) : 0;
}

getDuration() {
return this.videoEl.duration ? parseInt(this.videoEl.duration, 10) : 0;
}

pauseOtherVideos() {
if (this.currentlyPlayingVideo && this.currentlyPlayingVideo !== this.videoEl) {
this.currentlyPlayingVideo.pause();
Expand Down
23 changes: 23 additions & 0 deletions test/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,29 @@ describe('Video', () => {

});

describe('#getDuration', () => {
let video;

beforeEach(() => {
video = new Video(containerEl);
video.videoEl = {};
});

afterEach(() => {
video = undefined;
});

it('should return 0 if duration is not set', () => {
video.getDuration().should.equal(0);
});

it('should return the duration of the video as a integer', () => {
video.videoEl.duration = 22.46324646;
video.getDuration().should.equal(22);
});

});

describe('#getData', () => {

let fetchStub;
Expand Down

0 comments on commit d7b46f7

Please sign in to comment.