Added ended and playing getters

This commit is contained in:
Sam Potts
2017-11-20 10:48:28 +11:00
parent dc391c98c6
commit feae00224e
7 changed files with 34 additions and 9 deletions

View File

@ -254,6 +254,13 @@ const youtube = {
},
});
// Ended
Object.defineProperty(player.media, 'ended', {
get() {
return player.currentTime === player.duration;
},
});
// Get available speeds
if (player.config.controls.includes('settings') && player.config.settings.includes('speed')) {
controls.setSpeedMenu.call(player, instance.getAvailablePlaybackRates());
@ -316,6 +323,8 @@ const youtube = {
// 5 Video cued
switch (event.data) {
case 0:
player.media.paused = true;
// YouTube doesn't support loop for a single video, so mimick it.
if (player.media.loop) {
// YouTube needs a call to `stopVideo` before playing again
@ -323,21 +332,19 @@ const youtube = {
instance.playVideo();
} else {
utils.dispatchEvent.call(player, player.media, 'ended');
player.media.paused = true;
}
break;
case 1:
player.media.paused = false;
player.media.seeking = false;
// If we were seeking, fire seeked event
if (player.media.seeking) {
utils.dispatchEvent.call(player, player.media, 'seeked');
}
player.media.seeking = false;
utils.dispatchEvent.call(player, player.media, 'play');
utils.dispatchEvent.call(player, player.media, 'playing');