javascript - What is the proper way to read the video elements/attributes in video.js? -
i needed read , modify of tags , attributes in video element, uses video.js player. have been able read information using getelementsbytagname , getattribute, shown in code below. hoping there easier/better/best way through video.js (5.6.0).
var video = document.getelementsbytagname('video')[0]; var poster = video.getattribute('poster'); var sources = video.getelementsbytagname('source'); var tracks = video.getelementsbytagname('track'); if (poster != null) { var newposter = addchk(poster, "p"); // generates modified source video.setattribute('poster', newposter); } (var = 0; < sources.length; i++) { var s = sources[i].getattribute('src'); s = addchk(s,"f"); // generates modified source sources[i].setattribute('src', s); } (var = 0; < tracks.length; i++) { var s = tracks[i].getattribute('src'); s = addchk(s, "c"); // generates modified source tracks[i].setattribute('src', s); }
thanks.
as you're using video.js should use api these. directly modifying video element after player creation won't work expected, , if ever have different playback tech in use (such flash on ie8) there won't video element.
var player = videojs('my_player_id'); // get/set poster: console.log(player.poster()); player.poster('//example.com/poster.jpg'); // source: console.log(player.currentsrc()); // update source: player.src({src: '//example.com/video.mp4', type: 'video/mp4'}); // multiple sources: player.src([ {src: '//example.com/video.m3u8', type: 'application/x-mpegurl'}, {src: '//example.com/video.mp4', type: 'video/mp4'} ]);
for updating tracks you'll need remove existing track(s) before adding for now.
// remove tracks: var tracks = player.texttracks(); (i = 0; i<tracks.length;i++) { player.removeremotetexttrack(tracks[i]); } // add track player.addremotetexttrack({ kind: 'captions', src: '//example.com/captions.vtt', srclang: 'is', label: 'íslenska' });
Comments
Post a Comment