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

Reset player on source change. closes #1050 #1124

Closed
wants to merge 3 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+55 −15
Diff settings

Always

Just for now

View
@@ -77,20 +77,7 @@ vjs.Player = vjs.Component.extend({
// this.addClass('vjs-touch-enabled');
// }
// Firstplay event implimentation. Not sold on the event yet.
// Could probably just check currentTime==0?
this.one('play', function(e){
var fpEvent = { type: 'firstplay', target: this.el_ };
// Using vjs.trigger so we can check if default was prevented
var keepGoing = vjs.trigger(this.el_, fpEvent);
if (!keepGoing) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
}
});
this.on('loadstart', this.onLoadStart);
this.on('ended', this.onEnded);
this.on('play', this.onPlay);
this.on('firstplay', this.onFirstPlay);
@@ -407,7 +394,29 @@ vjs.Player.prototype.stopTrackingCurrentTime = function(){ clearInterval(this.cu
* Fired when the user agent begins looking for media data
* @event loadstart
*/
vjs.Player.prototype.onLoadStart;
vjs.Player.prototype.onLoadStart = function() {
// remove any first play listeners that weren't triggered from a previous video.
this.off('play', initFirstPlay);
this.one('play', initFirstPlay);
vjs.removeClass(this.el_, 'vjs-has-started');
};
/**
* Need to create this outside the scope of onLoadStart so it
* can be added and removed (to avoid piling first play listeners).
*/

This comment has been minimized.

@heff

heff Apr 1, 2014

Member

@mmcc can you add an @private tag after the description here? Otherwise this will get added to the docs. Either that or use a // comment.

@heff

heff Apr 1, 2014

Member

@mmcc can you add an @private tag after the description here? Otherwise this will get added to the docs. Either that or use a // comment.

This comment has been minimized.

@mmcc

mmcc Apr 2, 2014

Member

Who wouldn't want to see these comments in the docs?!

@mmcc

mmcc Apr 2, 2014

Member

Who wouldn't want to see these comments in the docs?!

function initFirstPlay(e) {
var fpEvent = { type: 'firstplay', target: this.el_ };
// Using vjs.trigger so we can check if default was prevented
var keepGoing = vjs.trigger(this.el_, fpEvent);
if (!keepGoing) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
}
}
/**
* Fired when the player has initial duration and dimension information
View
@@ -371,3 +371,34 @@ test('should register players with generated ids', function(){
equal(player.el().id, player.id(), 'the player and element ids are equal');
ok(vjs.players[id], 'the generated id is registered');
});
test('should not add multiple first play events despite subsequent loads', function() {
expect(1);
var player = PlayerTest.makePlayer({});
player.on('firstplay', function(){
ok('First play should fire once.');
});
// Checking to make sure onLoadStart removes first play listener before adding a new one.
player.trigger('loadstart');
player.trigger('loadstart');
player.trigger('play');
});
test('should remove vjs-has-started class', function(){
expect(3);
var player = PlayerTest.makePlayer({});
player.trigger('loadstart');
player.trigger('play');
ok(player.el().className.indexOf('vjs-has-started') !== -1, 'vjs-has-started class added');
player.trigger('loadstart');
ok(player.el().className.indexOf('vjs-has-started') === -1, 'vjs-has-started class removed');
player.trigger('play');
ok(player.el().className.indexOf('vjs-has-started') !== -1, 'vjs-has-started class added again');
});
ProTip! Use n and p to navigate between commits in a pull request.