aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-videojs-plugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/peertube-videojs-plugin.ts')
-rw-r--r--client/src/assets/player/peertube-videojs-plugin.ts35
1 files changed, 25 insertions, 10 deletions
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts
index 60c291a50..290d88724 100644
--- a/client/src/assets/player/peertube-videojs-plugin.ts
+++ b/client/src/assets/player/peertube-videojs-plugin.ts
@@ -68,9 +68,7 @@ class PeerTubePlugin extends Plugin {
68 constructor (player: videojs.Player, options: PeertubePluginOptions) { 68 constructor (player: videojs.Player, options: PeertubePluginOptions) {
69 super(player, options) 69 super(player, options)
70 70
71 // Fix canplay event on google chrome by disabling default videojs autoplay 71 this.autoplay = options.autoplay
72 this.autoplay = this.player.options_.autoplay
73 this.player.options_.autoplay = false
74 72
75 this.startTime = options.startTime 73 this.startTime = options.startTime
76 this.videoFiles = options.videoFiles 74 this.videoFiles = options.videoFiles
@@ -190,12 +188,7 @@ class PeerTubePlugin extends Plugin {
190 188
191 if (err) return this.fallbackToHttp(done) 189 if (err) return this.fallbackToHttp(done)
192 190
193 if (!this.player.paused()) { 191 if (!this.player.paused()) return this.tryToPlay(done)
194 const playPromise = this.player.play()
195 if (playPromise !== undefined) return playPromise.then(done)
196
197 return done()
198 }
199 192
200 return done() 193 return done()
201 }) 194 })
@@ -264,6 +257,25 @@ class PeerTubePlugin extends Plugin {
264 this.trigger('autoResolutionUpdate') 257 this.trigger('autoResolutionUpdate')
265 } 258 }
266 259
260 private tryToPlay (done?: Function) {
261 if (!done) done = function () { /* empty */ }
262
263 const playPromise = this.player.play()
264 if (playPromise !== undefined) {
265 return playPromise.then(done)
266 .catch(err => {
267 console.error(err)
268 this.player.pause()
269 this.player.posterImage.show()
270 this.player.removeClass('vjs-has-autoplay')
271
272 return done()
273 })
274 }
275
276 return done()
277 }
278
267 private seek (time: number) { 279 private seek (time: number) {
268 this.player.currentTime(time) 280 this.player.currentTime(time)
269 this.player.handleTechSeeked_() 281 this.player.handleTechSeeked_()
@@ -317,7 +329,10 @@ class PeerTubePlugin extends Plugin {
317 if (this.autoplay === true) { 329 if (this.autoplay === true) {
318 this.player.posterImage.hide() 330 this.player.posterImage.hide()
319 331
320 this.updateVideoFile(undefined, 0, () => this.seek(this.startTime)) 332 this.updateVideoFile(undefined, 0, () => {
333 this.seek(this.startTime)
334 this.tryToPlay()
335 })
321 } else { 336 } else {
322 // Proxy first play 337 // Proxy first play
323 const oldPlay = this.player.play.bind(this.player) 338 const oldPlay = this.player.play.bind(this.player)