player: call videojs.destroy() when transitioning

This commit is contained in:
calzoneman 2016-03-02 19:31:29 -08:00
parent e07cc0f5aa
commit d913f02657
4 changed files with 37 additions and 5 deletions

View file

@ -32,3 +32,5 @@ window.Player = class Player
getVolume: (cb) ->
cb(VOLUME)
destroy: ->

View file

@ -16,6 +16,12 @@ TYPE_MAP =
im: ImgurPlayer
window.loadMediaPlayer = (data) ->
try
if window.PLAYER
window.PLAYER.destroy()
catch error
console.error error
if data.meta.direct and data.type != 'gd'
try
window.PLAYER = new VideoJSPlayer(data)

View file

@ -131,6 +131,7 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
# existing player object, however it appears to be pretty glitchy when
# a video can't be played (either previous or next video). It's safer
# to just reset the entire thing.
@destroy()
@loadPlayer(data)
play: ->
@ -165,3 +166,8 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
cb(@player.volume())
else
cb(VOLUME)
destroy: ->
removeOld()
if @player
@player.dispose()

View file

@ -46,6 +46,8 @@
return cb(VOLUME);
};
Player.prototype.destroy = function() {};
return Player;
})();
@ -587,6 +589,7 @@
VideoJSPlayer.prototype.load = function(data) {
this.setMediaProperties(data);
this.destroy();
return this.loadPlayer(data);
};
@ -636,6 +639,13 @@
}
};
VideoJSPlayer.prototype.destroy = function() {
removeOld();
if (this.player) {
return this.player.dispose();
}
};
return VideoJSPlayer;
})(Player);
@ -1259,19 +1269,27 @@
};
window.loadMediaPlayer = function(data) {
var e, error1, error2;
var e, error, error1, error2, error3;
try {
if (window.PLAYER) {
window.PLAYER.destroy();
}
} catch (error1) {
error = error1;
console.error(error);
}
if (data.meta.direct && data.type !== 'gd') {
try {
return window.PLAYER = new VideoJSPlayer(data);
} catch (error1) {
e = error1;
} catch (error2) {
e = error2;
return console.error(e);
}
} else if (data.type in TYPE_MAP) {
try {
return window.PLAYER = TYPE_MAP[data.type](data);
} catch (error2) {
e = error2;
} catch (error3) {
e = error3;
return console.error(e);
}
}