Avoid bug at init

This commit is contained in:
Thomas Forgione 2021-06-21 11:21:13 +02:00
parent e26971d995
commit d1bd418e89
1 changed files with 28 additions and 26 deletions

View File

@ -36,37 +36,39 @@ function setupApp(app) {
let hls; let hls;
app.ports.polymnyVideoInit.subscribe(function(arg) { app.ports.polymnyVideoInit.subscribe(function(arg) {
const video = document.getElementById(arg[0]); requestAnimationFrame(function() {
if (Hls.isSupported()) { const video = document.getElementById(arg[0]);
hls = new Hls(); if (Hls.isSupported()) {
window.hls = hls; hls = new Hls();
hls.loadSource(arg[1]); window.hls = hls;
hls.loadSource(arg[1]);
hls.on(Hls.Events.MANIFEST_PARSED, function(event, data) { hls.on(Hls.Events.MANIFEST_PARSED, function(event, data) {
const availableQualities = hls.levels.map((l) => l.height); const availableQualities = hls.levels.map((l) => l.height);
availableQualities.unshift(0); availableQualities.unshift(0);
app.ports.polymnyVideoNowHasQualities.send(availableQualities); app.ports.polymnyVideoNowHasQualities.send(availableQualities);
});
hls.on(Hls.Events.LEVEL_SWITCHED, function(event, data) {
app.ports.polymnyVideoNowHasQuality.send({
auto: hls.autoLevelEnabled,
height: hls.levels[data.level].height
}); });
})
hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, function(event, data) { hls.on(Hls.Events.LEVEL_SWITCHED, function(event, data) {
app.ports.polymnyVideoNowHasSubtitles.send(data.subtitleTracks); app.ports.polymnyVideoNowHasQuality.send({
}); auto: hls.autoLevelEnabled,
height: hls.levels[data.level].height
});
})
hls.on(Hls.Events.SUBTITLE_TRACK_SWITCH, function(event, data) { hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, function(event, data) {
app.ports.polymnyVideoNowHasSubtitleTrack.send(data.id === -1 ? null : hls.subtitleTracks[data.id]); app.ports.polymnyVideoNowHasSubtitles.send(data.subtitleTracks);
}); });
hls.attachMedia(video); hls.on(Hls.Events.SUBTITLE_TRACK_SWITCH, function(event, data) {
} else if (video.canPlayType('application/vnd.apple.mpegurl')) { app.ports.polymnyVideoNowHasSubtitleTrack.send(data.id === -1 ? null : hls.subtitleTracks[data.id]);
video.src = arg[1]; });
}
hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = arg[1];
}
});
}); });
app.ports.polymnyVideoPlayPause.subscribe(function(arg) { app.ports.polymnyVideoPlayPause.subscribe(function(arg) {