Skip to content

Commit

Permalink
fix(viewer): move autoplay after loadUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Sep 5, 2019
1 parent d2a47bc commit 5b6f76c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/lib/viewers/media/DashViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,13 @@ class DashViewer extends VideoBaseViewer {
return;
}

this.loadUI();

if (this.isAutoplayEnabled()) {
this.autoplay();
}

this.calculateVideoDimensions();
this.loadUI();
this.loadFilmStrip();
this.resize();
this.handleVolume();
Expand Down
18 changes: 9 additions & 9 deletions src/lib/viewers/media/MediaBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ class MediaBaseViewer extends BaseViewer {
.then(() => {
this.startLoadTimer();
this.mediaEl.src = this.mediaUrl;
if (this.isAutoplayEnabled()) {
this.autoplay();
}
})
.catch(this.handleAssetError);
}
Expand All @@ -203,17 +200,20 @@ class MediaBaseViewer extends BaseViewer {
if (this.destroyed) {
return;
}

this.loadUI();

if (this.isAutoplayEnabled()) {
this.autoplay();
}

this.setMediaTime(this.startTimeInSeconds);
this.resize();
this.handleVolume();

this.loaded = true;
this.emit(VIEWER_EVENT.load);

this.loadUI();
// If media is muted because of auto-play,
// the volume icon should be updated after the UI is loaded
this.updateVolumeIcon();
this.resize();

// Make media element visible after resize
this.showMedia();

Expand Down
24 changes: 10 additions & 14 deletions src/lib/viewers/media/__tests__/MediaBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ describe('lib/viewers/media/MediaBaseViewer', () => {
beforeEach(() => {
media.mediaEl = document.createElement('video');
media.mediaEl.addEventListener = sandbox.stub();
sandbox.stub(media, 'isAutoplayEnabled').returns(false);
sandbox.stub(media, 'autoplay');
});

it('should load mediaUrl in the media element', () => {
Expand All @@ -138,16 +136,6 @@ describe('lib/viewers/media/MediaBaseViewer', () => {
});
});

it('should autoplay if enabled', () => {
media.isAutoplayEnabled.returns(true);
sandbox.stub(media, 'getRepStatus').returns({ getPromise: () => Promise.resolve() });
media.mediaEl = document.createElement('video');

return media.load().then(() => {
expect(media.autoplay).to.be.called;
});
});

it('should invoke startLoadTimer()', () => {
sandbox.stub(media, 'startLoadTimer');
sandbox.stub(media, 'getRepStatus').returns({ getPromise: () => Promise.resolve() });
Expand All @@ -163,7 +151,6 @@ describe('lib/viewers/media/MediaBaseViewer', () => {
sandbox.stub(media, 'handleVolume');
sandbox.stub(media, 'emit');
sandbox.stub(media, 'loadUI');
sandbox.stub(media, 'updateVolumeIcon');
sandbox.stub(media, 'resize');
sandbox.stub(media, 'showMedia');

Expand All @@ -174,11 +161,20 @@ describe('lib/viewers/media/MediaBaseViewer', () => {
expect(media.loaded).to.be.true;
expect(media.emit).to.be.calledWith(VIEWER_EVENT.load);
expect(media.loadUI).to.be.called;
expect(media.updateVolumeIcon).to.be.called;
expect(media.resize).to.be.called;
expect(media.showMedia).to.be.called;
expect(document.activeElement).to.equal(media.mediaContainerEl);
});

it('should autoplay if enabled', () => {
sandbox.stub(media, 'isAutoplayEnabled').returns(true);
sandbox.stub(media, 'autoplay');
media.mediaEl = document.createElement('video');

media.loadeddataHandler();

expect(media.autoplay).to.be.called;
});
});

describe('showMedia()', () => {
Expand Down

0 comments on commit 5b6f76c

Please sign in to comment.