Skip to content

Commit

Permalink
playing and play events shouldn't be triggered while buffering or see…
Browse files Browse the repository at this point in the history
…king, avoid throwing and breaking the player when it is destroyed faster than expected
  • Loading branch information
varemenos committed Apr 24, 2017
1 parent 893a92c commit 7c460fe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
17 changes: 13 additions & 4 deletions dist/Youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ THE SOFTWARE. */
dispose: function() {
if (this.ytPlayer) {
//Dispose of the YouTube Player
this.ytPlayer.stopVideo();
this.ytPlayer.destroy();
try {
this.ytPlayer.stopVideo();
this.ytPlayer.destroy();
} catch (e) {
if (e.message !== 'this.ytPlayer.stopVideo is not a function') {
console.log(e);
}
}
} else {
//YouTube API hasn't finished loading or the player is already disposed
var index = Youtube.apiReadyQueue.indexOf(this);
Expand Down Expand Up @@ -284,12 +290,15 @@ THE SOFTWARE. */
case YT.PlayerState.PLAYING:
this.trigger('timeupdate');
this.trigger('durationchange');
this.trigger('playing');
this.trigger('play');

if (this.isSeeking) {
this.onSeeked();
}

if (!this.isSeeking && state !== YT.PlayerState.BUFFERING) {
this.trigger('playing');
this.trigger('play');
}
break;

case YT.PlayerState.PAUSED:
Expand Down
Loading

0 comments on commit 7c460fe

Please sign in to comment.