From d7b46f7405d3bbdc1ff3bad6788388e7fd10dc49 Mon Sep 17 00:00:00 2001 From: Matt Chadburn Date: Thu, 5 Jan 2017 19:05:15 +0000 Subject: [PATCH] Video duration is an integer By default the duration is reported as `ss.mm`, often to ~12 decimal places, which makes grouping at reporting stage less useful. --- src/js/video.js | 6 +++++- test/video.test.js | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/js/video.js b/src/js/video.js index 51b2bd4..f8244a8 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -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 }); @@ -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(); diff --git a/test/video.test.js b/test/video.test.js index 3567ec4..51f4802 100644 --- a/test/video.test.js +++ b/test/video.test.js @@ -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;