diff --git a/js/caption.js b/js/caption.js index 200e34ff..b91bdbaf 100644 --- a/js/caption.js +++ b/js/caption.js @@ -302,15 +302,19 @@ var caption = function () { var video = document.getElementById(playerId); - video.addEventListener("loadedmetadata", function() { - //var track = document.createElement("track"); - var track = document.getElementById(playerId+'-vtt'); - track.kind = "captions"; - track.label = "English"; - track.srclang = "en"; - track.src = "data:text/vtt,"+encodeURIComponent(captionsVtt); + if (video !== null) { + video.addEventListener("loadedmetadata", function() { + //var track = document.createElement("track"); + var track = document.getElementById(playerId+'-vtt'); + track.kind = "captions"; + track.label = "English"; + track.srclang = "en"; + track.src = "data:text/vtt,"+encodeURIComponent(captionsVtt); + video.textTracks[0].mode = "showing"; + }); + video.textTracks[0].mode = "showing"; - }); + } video.textTracks[0].mode = "showing";