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) -> getVolume: (cb) ->
cb(VOLUME) cb(VOLUME)
destroy: ->

View File

@ -16,6 +16,12 @@ TYPE_MAP =
im: ImgurPlayer im: ImgurPlayer
window.loadMediaPlayer = (data) -> window.loadMediaPlayer = (data) ->
try
if window.PLAYER
window.PLAYER.destroy()
catch error
console.error error
if data.meta.direct and data.type != 'gd' if data.meta.direct and data.type != 'gd'
try try
window.PLAYER = new VideoJSPlayer(data) 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 # 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 # a video can't be played (either previous or next video). It's safer
# to just reset the entire thing. # to just reset the entire thing.
@destroy()
@loadPlayer(data) @loadPlayer(data)
play: -> play: ->
@ -165,3 +166,8 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
cb(@player.volume()) cb(@player.volume())
else else
cb(VOLUME) cb(VOLUME)
destroy: ->
removeOld()
if @player
@player.dispose()

View File

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