]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Smooth resolution change?
authorChocobozzz <me@florianbigard.com>
Fri, 8 Jun 2018 13:01:22 +0000 (15:01 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 8 Jun 2018 13:01:22 +0000 (15:01 +0200)
client/src/assets/player/peertube-videojs-plugin.ts

index e4fea0991901159fdfedd3d21bfbe55782ae99ab..057bc4b2a9be9de8f8822d9bdc7483d8931661fc 100644 (file)
@@ -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)