Embed: dashjs trackswitching using generic method

This commit is contained in:
Cat 2019-04-25 14:57:05 +02:00
parent 80a3618bc4
commit 7cf115d79a
2 changed files with 1 additions and 67 deletions

View file

@ -135,72 +135,6 @@ p.prototype.build = function (MistVideo,callback) {
MistVideo.player.dash.attachSource(url);
};
//trackswitching
MistVideo.player.api.setTrack = function(type,id){
var meta = MistUtil.tracks.parse(MistVideo.info.meta.tracks);
if ((!(type in meta)) || ((!(id in meta[type]) && (id != "none")))) {
MistVideo.log("Skipping trackselection of "+type+" track "+id+" because it does not exist");
return;
}
//figure out what the track number is
//for dash: 0 lowest bitrate, going up
//get the relevant tracks
var mistTracks = [];
for (var i in MistVideo.info.meta.tracks) {
var t = MistVideo.info.meta.tracks[i];
if (t.type == type) {
mistTracks.push(t);
}
}
//sort by bitrate
MistUtil.array.multiSort(mistTracks,["bps"]);
var n = false;
for (var i in mistTracks) {
var trackid = ("idx" in mistTracks[i] ? mistTracks[i].idx : mistTracks[i].trackid);
if (trackid == id) {
n = i;
break;
}
}
if (n === false) {
return false; //track not found
}
me.dash.setAutoSwitchQualityFor(type,false); //turn off ABR rules //TODO do we want this by default?
me.dash.setFastSwitchEnabled(true); //show the new track asap
me.dash.setQualityFor(type,n);
//dash does change the track, but is appended to the buffer, so it seems to take a while..
return true; //track found and change requested
}
//react to automatic trackswitching
me.dash.on("qualityChangeRendered",function(e){
//the newQuality-th track of type mediaType is being selected
//figure out the track id
//for dash: 0 lowest bitrate, going up
//get the relevant tracks
var mistTracks = [];
for (var i in MistVideo.info.meta.tracks) {
var t = MistVideo.info.meta.tracks[i];
if (t.type == e.mediaType) {
mistTracks.push(t);
}
}
//sort by bitrate
MistUtil.array.multiSort(mistTracks,["bps"]);
//get mist's id for the track
var id = ("idx" in mistTracks[e.newQuality] ? mistTracks[e.newQuality].idx : mistTracks[e.newQuality].trackid);
//create an event to pass this to the skin
MistUtil.event.send("playerUpdate_trackChanged",{
type: e.mediaType,
trackid: id
},MistVideo.video);
});
var subsloaded = false;
me.dash.on("allTextTracksAdded",function(){
subsloaded = true;