diff options
author | Chocobozzz <me@florianbigard.com> | 2018-04-05 17:06:59 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-04-05 17:12:22 +0200 |
commit | f37bad639b36d35c29a464dc52123a1e7c9cd28a (patch) | |
tree | 376ff9d09b091610cb943ee5fd4eebc7a17e4c22 /client/src/assets/player/peertube-videojs-plugin.ts | |
parent | 7ee4a4af0b01040e3896453ee68b3d429dc45cd4 (diff) | |
download | PeerTube-f37bad639b36d35c29a464dc52123a1e7c9cd28a.tar.gz PeerTube-f37bad639b36d35c29a464dc52123a1e7c9cd28a.tar.zst PeerTube-f37bad639b36d35c29a464dc52123a1e7c9cd28a.zip |
Add ability to set a start time
Diffstat (limited to 'client/src/assets/player/peertube-videojs-plugin.ts')
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 2eddcb1d8..ddb73d074 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts | |||
@@ -36,6 +36,7 @@ class PeerTubePlugin extends Plugin { | |||
36 | private readonly playerElement: HTMLVideoElement | 36 | private readonly playerElement: HTMLVideoElement |
37 | 37 | ||
38 | private readonly autoplay: boolean = false | 38 | private readonly autoplay: boolean = false |
39 | private readonly startTime: number = 0 | ||
39 | private readonly savePlayerSrcFunction: Function | 40 | private readonly savePlayerSrcFunction: Function |
40 | private readonly videoFiles: VideoFile[] | 41 | private readonly videoFiles: VideoFile[] |
41 | private readonly videoViewUrl: string | 42 | private readonly videoViewUrl: string |
@@ -71,6 +72,7 @@ class PeerTubePlugin extends Plugin { | |||
71 | this.autoplay = this.player.options_.autoplay | 72 | this.autoplay = this.player.options_.autoplay |
72 | this.player.options_.autoplay = false | 73 | this.player.options_.autoplay = false |
73 | 74 | ||
75 | this.startTime = options.startTime | ||
74 | this.videoFiles = options.videoFiles | 76 | this.videoFiles = options.videoFiles |
75 | this.videoViewUrl = options.videoViewUrl | 77 | this.videoViewUrl = options.videoViewUrl |
76 | this.videoDuration = options.videoDuration | 78 | this.videoDuration = options.videoDuration |
@@ -94,7 +96,7 @@ class PeerTubePlugin extends Plugin { | |||
94 | this.runViewAdd() | 96 | this.runViewAdd() |
95 | 97 | ||
96 | this.player.one('play', () => { | 98 | this.player.one('play', () => { |
97 | // Don't run immediately scheduler, wait some seconds the TCP connections are maid | 99 | // Don't run immediately scheduler, wait some seconds the TCP connections are made |
98 | this.runAutoQualitySchedulerTimer = setTimeout(() => { | 100 | this.runAutoQualitySchedulerTimer = setTimeout(() => { |
99 | this.runAutoQualityScheduler() | 101 | this.runAutoQualityScheduler() |
100 | }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER) | 102 | }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER) |
@@ -234,10 +236,7 @@ class PeerTubePlugin extends Plugin { | |||
234 | } | 236 | } |
235 | 237 | ||
236 | const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId) | 238 | const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId) |
237 | this.updateVideoFile(newVideoFile, delay, () => { | 239 | this.updateVideoFile(newVideoFile, delay, () => this.seek(currentTime)) |
238 | this.player.currentTime(currentTime) | ||
239 | this.player.handleTechSeeked_() | ||
240 | }) | ||
241 | } | 240 | } |
242 | 241 | ||
243 | flushVideoFile (videoFile: VideoFile, destroyRenderer = true) { | 242 | flushVideoFile (videoFile: VideoFile, destroyRenderer = true) { |
@@ -263,6 +262,11 @@ class PeerTubePlugin extends Plugin { | |||
263 | this.trigger('autoResolutionUpdate') | 262 | this.trigger('autoResolutionUpdate') |
264 | } | 263 | } |
265 | 264 | ||
265 | private seek (time: number) { | ||
266 | this.player.currentTime(time) | ||
267 | this.player.handleTechSeeked_() | ||
268 | } | ||
269 | |||
266 | private getAppropriateFile (averageDownloadSpeed?: number): VideoFile { | 270 | private getAppropriateFile (averageDownloadSpeed?: number): VideoFile { |
267 | if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined | 271 | if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined |
268 | if (this.videoFiles.length === 1) return this.videoFiles[0] | 272 | if (this.videoFiles.length === 1) return this.videoFiles[0] |
@@ -310,12 +314,18 @@ class PeerTubePlugin extends Plugin { | |||
310 | 314 | ||
311 | if (this.autoplay === true) { | 315 | if (this.autoplay === true) { |
312 | this.player.posterImage.hide() | 316 | this.player.posterImage.hide() |
313 | this.updateVideoFile(undefined, 0, () => this.player.play()) | 317 | this.updateVideoFile(undefined, 0, () => { |
318 | this.seek(this.startTime) | ||
319 | this.player.play() | ||
320 | }) | ||
314 | } else { | 321 | } else { |
315 | // Proxy first play | 322 | // Proxy first play |
316 | const oldPlay = this.player.play.bind(this.player) | 323 | const oldPlay = this.player.play.bind(this.player) |
317 | this.player.play = () => { | 324 | this.player.play = () => { |
318 | this.updateVideoFile(undefined, 0, () => oldPlay) | 325 | this.updateVideoFile(undefined, 0, () => { |
326 | this.seek(this.startTime) | ||
327 | oldPlay() | ||
328 | }) | ||
319 | this.player.play = oldPlay | 329 | this.player.play = oldPlay |
320 | } | 330 | } |
321 | } | 331 | } |