]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/peertube-videojs-plugin.ts
Fix player play exception on chromium
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-videojs-plugin.ts
index 4ba37b7d92ebe195105a33184f09d634dac9677a..8c131c9e9db9888f0299188983bfb048309fa5b7 100644 (file)
@@ -1,8 +1,8 @@
 // Big thanks to: https://github.com/kmoskwiak/videojs-resolution-switcher
 
-import videojs, { Player } from 'video.js'
+import * as videojs from 'video.js'
 import * as WebTorrent from 'webtorrent'
-import { VideoFile } from '../../../../shared'
+import { VideoFile } from '../../../../shared/models/videos/video.model'
 
 import { renderVideo } from './video-renderer'
 
@@ -27,7 +27,7 @@ const webtorrent = new WebTorrent({ dht: false })
 
 const MenuItem = videojsUntyped.getComponent('MenuItem')
 const ResolutionMenuItem = videojsUntyped.extend(MenuItem, {
-  constructor: function (player: Player, options) {
+  constructor: function (player: videojs.Player, options) {
     options.selectable = true
     MenuItem.call(this, player, options)
 
@@ -235,9 +235,7 @@ const peertubePlugin = function (options: PeertubePluginOptions) {
         if (err) return handleError(err)
 
         this.renderer = renderer
-        player.play()
-
-        return done()
+        player.play().then(done)
       })
     })
 
@@ -283,6 +281,12 @@ const peertubePlugin = function (options: PeertubePluginOptions) {
     }
   }
 
+  player.setVideoFiles = function (files: VideoFile[]) {
+    player.videoFiles = files
+
+    player.updateVideoFile(undefined, () => player.play())
+  }
+
   player.ready(function () {
     const controlBar = player.controlBar
 
@@ -317,10 +321,14 @@ const peertubePlugin = function (options: PeertubePluginOptions) {
       player.updateVideoFile()
     } else {
       player.one('play', () => {
-        // Pause, we wait the video to load before
-        player.pause()
-
-        player.updateVideoFile(undefined, () => player.play())
+        // On firefox, we need to wait to load the video before playing
+        if (navigator.userAgent.toLowerCase().indexOf('firefox') !== -1) {
+          player.pause()
+          player.updateVideoFile(undefined, () => player.play())
+          return
+        }
+
+        player.updateVideoFile(undefined)
       })
     }