From b666605c96ddb9e5d5025336ab3debe313b2ba73 Mon Sep 17 00:00:00 2001 From: Jeremy Press Date: Mon, 13 Nov 2017 17:04:41 -0800 Subject: [PATCH] Fix: Simplify video resize logic (#480) --- src/lib/viewers/media/DashViewer.js | 17 +++-------------- .../viewers/media/__tests__/DashViewer-test.js | 16 ---------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/src/lib/viewers/media/DashViewer.js b/src/lib/viewers/media/DashViewer.js index cd304a9a8..f9ecfdc84 100644 --- a/src/lib/viewers/media/DashViewer.js +++ b/src/lib/viewers/media/DashViewer.js @@ -507,28 +507,17 @@ class DashViewer extends VideoBaseViewer { // that larger than the current videoHeight. this.mediaEl.style.width = ''; - // Add a new width or height. Don't need to add both - // since the video will auto adjust the other dimension accordingly. - if (fullscreen.isFullscreen(this.containerEl)) { - // Case 1: Full screen mode, stretch the video - // to fit the whole screen irrespective of its width and height. - - if (this.aspect >= 1) { - this.mediaEl.style.width = `${viewport.width}px`; - } else { - this.mediaEl.style.width = `${viewport.height * this.aspect}px`; - } - } else if (width <= viewport.width && height <= viewport.height) { - // Case 2: The video ends up fitting within the viewport of preview + if (!fullscreen.isFullscreen(this.containerEl) && (width <= viewport.width && height <= viewport.height)) { + // Case 1: The video ends up fitting within the viewport of preview // For this case, just set the video player dimensions to match the // actual video's dimenstions. - if (this.aspect >= 1) { this.mediaEl.style.width = `${width}px`; } else { this.mediaEl.style.width = `${height * this.aspect}px`; } } else { + // Case 2: The video is now in fullscreen and needs to be scaled // Case 3: The video overflows the viewport of preview // For this case, try fitting in the video by reducing // either its width or its height. diff --git a/src/lib/viewers/media/__tests__/DashViewer-test.js b/src/lib/viewers/media/__tests__/DashViewer-test.js index 192424c43..fedbb22e9 100644 --- a/src/lib/viewers/media/__tests__/DashViewer-test.js +++ b/src/lib/viewers/media/__tests__/DashViewer-test.js @@ -838,22 +838,6 @@ describe('lib/viewers/media/DashViewer', () => { dash.resize(); expect(dash.mediaEl.style.width).to.equal('325px'); }); - - describe('Full screen mode', () => { - it('should set mediaEl width to viewport width if aspect ratio is >= 1', () => { - sandbox.stub(fullscreen, 'isFullscreen').returns(true); - dash.resize(); - expect(dash.mediaEl.style.width).to.equal('600px'); - }); - - it('should set mediaEl width to adjusted viewport height if aspect ratio is < 1', () => { - sandbox.stub(fullscreen, 'isFullscreen').returns(true); - dash.aspect = 0.5; - dash.resize(); - expect(dash.mediaEl.style.width).to.equal('325px'); - }); - }); - describe('Video fits in the viewport of preview', () => { it('should set mediaEl width to video width if aspect ratio is >= 1', () => { dash.resize();