Fix player resolution change that plays even if the video was paused
This commit is contained in:
parent
734a5ceb3d
commit
3baf9be283
|
@ -1,4 +1,4 @@
|
||||||
import { Component, OnInit } from '@angular/core'
|
import { Component, OnInit, OnDestroy } from '@angular/core'
|
||||||
import { ActivatedRoute } from '@angular/router'
|
import { ActivatedRoute } from '@angular/router'
|
||||||
import { AccountService } from '@app/shared/account/account.service'
|
import { AccountService } from '@app/shared/account/account.service'
|
||||||
import { Account } from '@app/shared/account/account.model'
|
import { Account } from '@app/shared/account/account.model'
|
||||||
|
@ -10,7 +10,7 @@ import { Subscription } from 'rxjs'
|
||||||
templateUrl: './accounts.component.html',
|
templateUrl: './accounts.component.html',
|
||||||
styleUrls: [ './accounts.component.scss' ]
|
styleUrls: [ './accounts.component.scss' ]
|
||||||
})
|
})
|
||||||
export class AccountsComponent implements OnInit {
|
export class AccountsComponent implements OnInit, OnDestroy {
|
||||||
account: Account
|
account: Account
|
||||||
|
|
||||||
private routeSub: Subscription
|
private routeSub: Subscription
|
||||||
|
|
|
@ -126,11 +126,15 @@ class PeerTubePlugin extends Plugin {
|
||||||
return this.currentVideoFile ? this.currentVideoFile.resolution.label : ''
|
return this.currentVideoFile ? this.currentVideoFile.resolution.label : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVideoFile (videoFile?: VideoFile, delay = 0, done?: () => void) {
|
updateVideoFile (
|
||||||
if (done === undefined) {
|
videoFile?: VideoFile,
|
||||||
done = () => { /* empty */ }
|
options: {
|
||||||
}
|
forcePlay?: boolean,
|
||||||
|
seek?: number,
|
||||||
|
delay?: number
|
||||||
|
} = {},
|
||||||
|
done: () => void = () => { /* empty */ }
|
||||||
|
) {
|
||||||
// Automatically choose the adapted video file
|
// Automatically choose the adapted video file
|
||||||
if (videoFile === undefined) {
|
if (videoFile === undefined) {
|
||||||
const savedAverageBandwidth = getAverageBandwidth()
|
const savedAverageBandwidth = getAverageBandwidth()
|
||||||
|
@ -153,7 +157,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
const previousVideoFile = this.currentVideoFile
|
const previousVideoFile = this.currentVideoFile
|
||||||
this.currentVideoFile = videoFile
|
this.currentVideoFile = videoFile
|
||||||
|
|
||||||
this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, delay, () => {
|
this.addTorrent(this.currentVideoFile.magnetUri, previousVideoFile, options, () => {
|
||||||
this.player.playbackRate(oldPlaybackRate)
|
this.player.playbackRate(oldPlaybackRate)
|
||||||
return done()
|
return done()
|
||||||
})
|
})
|
||||||
|
@ -161,17 +165,26 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.trigger('videoFileUpdate')
|
this.trigger('videoFileUpdate')
|
||||||
}
|
}
|
||||||
|
|
||||||
addTorrent (magnetOrTorrentUrl: string, previousVideoFile: VideoFile, delay = 0, done: Function) {
|
addTorrent (
|
||||||
|
magnetOrTorrentUrl: string,
|
||||||
|
previousVideoFile: VideoFile,
|
||||||
|
options: {
|
||||||
|
forcePlay?: boolean,
|
||||||
|
seek?: number,
|
||||||
|
delay?: number
|
||||||
|
},
|
||||||
|
done: Function
|
||||||
|
) {
|
||||||
console.log('Adding ' + magnetOrTorrentUrl + '.')
|
console.log('Adding ' + magnetOrTorrentUrl + '.')
|
||||||
|
|
||||||
const oldTorrent = this.torrent
|
const oldTorrent = this.torrent
|
||||||
const options = {
|
const torrentOptions = {
|
||||||
store: (chunkLength, storeOpts) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), {
|
store: (chunkLength, storeOpts) => new CacheChunkStore(new PeertubeChunkStore(chunkLength, storeOpts), {
|
||||||
max: 100
|
max: 100
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.torrent = webtorrent.add(magnetOrTorrentUrl, options, torrent => {
|
this.torrent = webtorrent.add(magnetOrTorrentUrl, torrentOptions, torrent => {
|
||||||
console.log('Added ' + magnetOrTorrentUrl + '.')
|
console.log('Added ' + magnetOrTorrentUrl + '.')
|
||||||
|
|
||||||
// Pause the old torrent
|
// Pause the old torrent
|
||||||
|
@ -183,19 +196,24 @@ class PeerTubePlugin extends Plugin {
|
||||||
|
|
||||||
// Render the video in a few seconds? (on resolution change for example, we wait some seconds of the new video resolution)
|
// Render the video in a few seconds? (on resolution change for example, we wait some seconds of the new video resolution)
|
||||||
this.addTorrentDelay = setTimeout(() => {
|
this.addTorrentDelay = setTimeout(() => {
|
||||||
|
const paused = this.player.paused()
|
||||||
|
|
||||||
this.flushVideoFile(previousVideoFile)
|
this.flushVideoFile(previousVideoFile)
|
||||||
|
|
||||||
const options = { autoplay: true, controls: true }
|
const renderVideoOptions = { autoplay: false, controls: true }
|
||||||
renderVideo(torrent.files[0], this.playerElement, options,(err, renderer) => {
|
renderVideo(torrent.files[0], this.playerElement, renderVideoOptions,(err, renderer) => {
|
||||||
this.renderer = renderer
|
this.renderer = renderer
|
||||||
|
|
||||||
if (err) return this.fallbackToHttp(done)
|
if (err) return this.fallbackToHttp(done)
|
||||||
|
|
||||||
if (!this.player.paused()) return this.tryToPlay(done)
|
return this.tryToPlay(err => {
|
||||||
|
if (err) return done(err)
|
||||||
|
|
||||||
return done()
|
if (options.seek) this.seek(options.seek)
|
||||||
|
if (options.forcePlay === false && paused === true) this.player.pause()
|
||||||
})
|
})
|
||||||
}, delay)
|
})
|
||||||
|
}, options.delay || 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.torrent.on('error', err => this.handleError(err))
|
this.torrent.on('error', err => this.handleError(err))
|
||||||
|
@ -213,7 +231,8 @@ class PeerTubePlugin extends Plugin {
|
||||||
// Magnet hash is not up to date with the torrent file, add directly the torrent file
|
// Magnet hash is not up to date with the torrent file, add directly the torrent file
|
||||||
if (err.message.indexOf('incorrect info hash') !== -1) {
|
if (err.message.indexOf('incorrect info hash') !== -1) {
|
||||||
console.error('Incorrect info hash detected, falling back to torrent file.')
|
console.error('Incorrect info hash detected, falling back to torrent file.')
|
||||||
return this.addTorrent(this.torrent['xs'], previousVideoFile, 0, done)
|
const options = { forcePlay: true }
|
||||||
|
return this.addTorrent(this.torrent['xs'], previousVideoFile, options, done)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.handleError(err)
|
return this.handleError(err)
|
||||||
|
@ -234,7 +253,12 @@ class PeerTubePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId)
|
const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId)
|
||||||
this.updateVideoFile(newVideoFile, delay, () => this.seek(currentTime))
|
const options = {
|
||||||
|
forcePlay: false,
|
||||||
|
delay,
|
||||||
|
seek: currentTime
|
||||||
|
}
|
||||||
|
this.updateVideoFile(newVideoFile, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
flushVideoFile (videoFile: VideoFile, destroyRenderer = true) {
|
flushVideoFile (videoFile: VideoFile, destroyRenderer = true) {
|
||||||
|
@ -342,10 +366,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
if (this.autoplay === true) {
|
if (this.autoplay === true) {
|
||||||
this.player.posterImage.hide()
|
this.player.posterImage.hide()
|
||||||
|
|
||||||
this.updateVideoFile(undefined, 0, () => {
|
this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
|
||||||
this.seek(this.startTime)
|
|
||||||
this.tryToPlay()
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
// Don't try on iOS that does not support MediaSource
|
// Don't try on iOS that does not support MediaSource
|
||||||
if (this.isIOS()) {
|
if (this.isIOS()) {
|
||||||
|
@ -359,7 +380,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.player.addClass('vjs-has-big-play-button-clicked')
|
this.player.addClass('vjs-has-big-play-button-clicked')
|
||||||
this.player.play = oldPlay
|
this.player.play = oldPlay
|
||||||
|
|
||||||
this.updateVideoFile(undefined, 0, () => this.seek(this.startTime))
|
this.updateVideoFile(undefined, { forcePlay: true, seek: this.startTime })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue