From 6d272f396c269b62537b3719fed4e2f2119b05d7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 8 Jun 2018 15:01:22 +0200 Subject: [PATCH] Smooth resolution change? --- .../assets/player/peertube-videojs-plugin.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index e4fea0991..057bc4b2a 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts @@ -185,6 +185,7 @@ class PeerTubePlugin extends Plugin { console.log('Adding ' + magnetOrTorrentUrl + '.') const oldTorrent = this.torrent + let fakeRenderer const torrentOptions = { store: (chunkLength, storeOpts) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), { max: 100 @@ -199,10 +200,37 @@ class PeerTubePlugin extends Plugin { oldTorrent.pause() // Pause does not remove actual peers (in particular the webseed peer) oldTorrent.removePeer(oldTorrent['ws']) + + // We use a fake renderer so we download correct pieces of the next file + // This way we'll be able to + if (options.delay) { + const fakeVideoElem = document.createElement('video') + renderVideo(torrent.files[0], fakeVideoElem, { autoplay: false, controls: false }, (err, renderer) => { + fakeRenderer = renderer + + if (err) { + console.error('Cannot render new torrent in fake video element.', err) + } + + // Load the future file at the correct time + fakeVideoElem.currentTime = this.player.currentTime() + (options.delay / 2000) + }) + } } // Render the video in a few seconds? (on resolution change for example, we wait some seconds of the new video resolution) this.addTorrentDelay = setTimeout(() => { + if (fakeRenderer) { + if (fakeRenderer.destroy) { + try { + fakeRenderer.destroy() + } catch (err) { + console.log('Cannot destroy correctly fake renderer.', err) + } + } + fakeRenderer = undefined + } + const paused = this.player.paused() this.flushVideoFile(previousVideoFile) -- 2.41.0