From bad5130c8ff76c96494f0918399a1976dc1a2278 Mon Sep 17 00:00:00 2001 From: Steve Heffernan Date: Wed, 14 May 2014 14:58:20 -0700 Subject: [PATCH] Fixed the loadstart event listener order so it's attached before the HTML5 tech triggers it. fixes #1208 fixes #1207 fixes #1193 --- src/js/media/html5.js | 6 ++++-- src/js/player.js | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/js/media/html5.js b/src/js/media/html5.js index 97214031a..6cb8ff46c 100644 --- a/src/js/media/html5.js +++ b/src/js/media/html5.js @@ -32,8 +32,10 @@ vjs.Html5 = vjs.MediaTechController.extend({ // If the element source is already set, we may have missed the loadstart event, and want to trigger it. // We don't want to set the source again and interrupt playback. if (source && this.el_.currentSrc === source.src && this.el_.networkState > 0) { - player.trigger('loadstart'); - + // wait for the player to be ready so the player listeners are attached + player.ready(function(){ + player.trigger('loadstart'); + }); // Otherwise set the source if one was provided. } else if (source) { this.el_.src = source.src; diff --git a/src/js/player.js b/src/js/player.js index cb112d890..5de75f9f4 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -58,6 +58,20 @@ vjs.Player = vjs.Component.extend({ // see enableTouchActivity in Component options.reportTouchActivity = false; + // Make sure the event listeners are the first things to happen when + // the player is ready. See #1208 + // If not, the tech might fire events before the listeners are attached. + this.ready(function(){ + this.on('loadstart', this.onLoadStart); + this.on('ended', this.onEnded); + this.on('play', this.onPlay); + this.on('firstplay', this.onFirstPlay); + this.on('pause', this.onPause); + this.on('progress', this.onProgress); + this.on('durationchange', this.onDurationChange); + this.on('fullscreenchange', this.onFullscreenChange); + }); + // Run base component initializing with new options. // Builds the element through createEl() // Inits and embeds any child components in opts @@ -77,15 +91,6 @@ vjs.Player = vjs.Component.extend({ // this.addClass('vjs-touch-enabled'); // } - this.on('loadstart', this.onLoadStart); - this.on('ended', this.onEnded); - this.on('play', this.onPlay); - this.on('firstplay', this.onFirstPlay); - this.on('pause', this.onPause); - this.on('progress', this.onProgress); - this.on('durationchange', this.onDurationChange); - this.on('fullscreenchange', this.onFullscreenChange); - // Make player easily findable by ID vjs.players[this.id_] = this;