Smooth resolution change?

pull/645/head
Chocobozzz 2018-06-08 15:01:22 +02:00
parent 91d9558963
commit 6d272f396c
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 28 additions and 0 deletions

View 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)