Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide the poster when play fires #1834

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,6 @@ vjs.Player.prototype.onLoadStart = function() {
} else {
// reset the hasStarted state
this.hasStarted(false);
this.one('play', function(){
this.hasStarted(true);
});
}
};

Expand Down Expand Up @@ -451,6 +448,12 @@ vjs.Player.prototype.onLoadedAllData;
vjs.Player.prototype.onPlay = function(){
this.removeClass('vjs-paused');
this.addClass('vjs-playing');

// hide the poster when the user hits play
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play
if (!this.hasStarted()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hasStarted method already handles this check, if you want to simplify this.

this.hasStarted(true);
}
};

/**
Expand Down
3 changes: 3 additions & 0 deletions test/unit/mediafaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ vjs.MediaFaker.prototype.volume = function(){ return 0; };
vjs.MediaFaker.prototype.muted = function(){ return false; };
vjs.MediaFaker.prototype.pause = function(){ return false; };
vjs.MediaFaker.prototype.paused = function(){ return true; };
vjs.MediaFaker.prototype.play = function() {
this.player().trigger('play');
};
vjs.MediaFaker.prototype.supportsFullScreen = function(){ return false; };
vjs.MediaFaker.prototype.buffered = function(){ return {}; };
vjs.MediaFaker.prototype.duration = function(){ return {}; };
Expand Down
19 changes: 19 additions & 0 deletions test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,25 @@ test('should set and update the poster value', function(){
player.dispose();
});

// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play
test('should hide the poster when play is called', function() {
var player = PlayerTest.makePlayer({
poster: 'https://example.com/poster.jpg'
});

equal(player.hasStarted(), false, 'the show poster flag is true before play');
player.play();
equal(player.hasStarted(), true, 'the show poster flag is false after play');

player.trigger('loadstart');
equal(player.hasStarted(),
false,
'the resource selection algorithm sets the show poster flag to true');

player.play();
equal(player.hasStarted(), true, 'the show poster flag is false after play');
});

test('should load a media controller', function(){
var player = PlayerTest.makePlayer({
preload: 'none',
Expand Down