From c28f3ef9ae6b7857e870a4b632949f37e8cab6af Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 24 Mar 2021 08:17:36 +0100 Subject: [PATCH] Support for HLS --- index.html | 14 ++++++++++++-- js/vd.js | 22 +++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index d41b618..0406ba1 100644 --- a/index.html +++ b/index.html @@ -23,14 +23,15 @@ if (app.ports !== undefined && app.ports.registerVideo !== undefined) { app.ports.registerVideo.subscribe(function(args) { window.scrollTo(0, 0); - var time = vd.parseTime(args[2]) || undefined; + var time = vd.parseTime(args[2]); + time = time || vd.parseTime(localStorage.getItem(args[0])); requestAnimationFrame(function() { if (args[0] !== lastId) { lastId = args[0]; player = vd.setup(args[0], { - v: args[1] + "/manifest.mpd", + v: args[1] + "/manifest.m3u8", t: time, focus: true }); @@ -38,6 +39,8 @@ player.currentTime(time); } }); + + setTimeout(recordPosition, 1000); }); } @@ -47,6 +50,13 @@ lastId = undefined; }); } + + function recordPosition() { + if (lastId !== undefined) { + localStorage.setItem(lastId, player.currentTime()); + setTimeout(recordPosition, 1000); + } + } diff --git a/js/vd.js b/js/vd.js index a7bc80f..1ba7d87 100644 --- a/js/vd.js +++ b/js/vd.js @@ -238,7 +238,7 @@ function createRepresentationButtons(player, menuButton = undefined) { let hls = player.tech({IWillNotUseThisInPlugins: true}).hls; - if (hls === undefined) { + if (hls === undefined || hls.representations === undefined) { setTimeout(() => createRepresentationButtons(player, menuButton), 500); return menuButton; } @@ -365,10 +365,16 @@ vd.setup = function(video, args) { } let player = videojs(video); - player.src({ - src, - type: 'application/dash+xml' - }); + if (src.endsWith('.mpd')) { + player.src({ + src, + type: 'application/dash+xml' + }); + } else { + player.src({ + src, + }); + } if (args.focus === true) { player.focus(); @@ -528,8 +534,10 @@ vd.setup = function(video, args) { controlBar.removeChild(fullscreenButton); let menuButton = createRepresentationButtons(player); - let speedButton = createSpeedButtons(player); - controlBar.addChild(speedButton, {}); + if (player.getAttribute('disable-speed') == undefined) { + let speedButton = createSpeedButtons(player); + controlBar.addChild(speedButton, {}); + } controlBar.addChild(menuButton, {}); controlBar.addChild(fullscreenButton, {});