b008ce80 by David LaPalomento

Merge pull request #99 from videojs/hotfix/tech-unloading

Don't blow up if the tech is disposed before player.ready(). For #88.
2 parents 76a27259 7d1ab655
...@@ -211,6 +211,10 @@ var ...@@ -211,6 +211,10 @@ var
211 if (lastSeekedTime) { 211 if (lastSeekedTime) {
212 return lastSeekedTime; 212 return lastSeekedTime;
213 } 213 }
214 // currentTime is zero while the tech is initializing
215 if (!this.el() || !this.el().vjs_getProperty) {
216 return 0;
217 }
214 return this.el().vjs_getProperty('currentTime'); 218 return this.el().vjs_getProperty('currentTime');
215 }; 219 };
216 220
...@@ -640,6 +644,11 @@ videojs.Hls.prototype.src = function(src) { ...@@ -640,6 +644,11 @@ videojs.Hls.prototype.src = function(src) {
640 this.mediaSource = mediaSource; 644 this.mediaSource = mediaSource;
641 initSource(player, mediaSource, src); 645 initSource(player, mediaSource, src);
642 this.player().ready(function() { 646 this.player().ready(function() {
647 // do nothing if the tech has been disposed already
648 // this can occur if someone sets the src in player.ready(), for instance
649 if (!self.el()) {
650 return;
651 }
643 self.el().vjs_src(source.src); 652 self.el().vjs_src(source.src);
644 }); 653 });
645 } 654 }
......
...@@ -1278,4 +1278,28 @@ test('re-emits mediachange events', function() { ...@@ -1278,4 +1278,28 @@ test('re-emits mediachange events', function() {
1278 strictEqual(mediaChanges, 1, 'fired mediachange'); 1278 strictEqual(mediaChanges, 1, 'fired mediachange');
1279 }); 1279 });
1280 1280
1281 test('can be disposed before finishing initialization', function() {
1282 var player = createPlayer(), readyHandlers = [];
1283 player.ready = function(callback) {
1284 readyHandlers.push(callback);
1285 };
1286 player.src({
1287 src: 'http://example.com/media.m3u8',
1288 type: 'application/vnd.apple.mpegurl'
1289 });
1290 player.src({
1291 src: 'http://example.com/media.mp4',
1292 type: 'video/mp4'
1293 });
1294 ok(readyHandlers.length > 0, 'registered a ready handler');
1295 try {
1296 while (readyHandlers.length) {
1297 readyHandlers.shift()();
1298 }
1299 ok(true, 'did not throw an exception');
1300 } catch (e) {
1301 ok(false, 'threw an exception');
1302 }
1303 });
1304
1281 })(window, window.videojs); 1305 })(window, window.videojs);
......