Skip to content

Commit

Permalink
Fix: Simplify video resize logic (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press committed Nov 14, 2017
1 parent 28fa161 commit b666605
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
17 changes: 3 additions & 14 deletions src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 0 additions & 16 deletions src/lib/viewers/media/__tests__/DashViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b666605

Please sign in to comment.