]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/peertube-player-manager.ts
Add audio support in upload
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-player-manager.ts
index 0ba9bcb1142267422055d96eef196e34defa532f..31cbc7dfd4c17c3b18f6b3cbcd2572de57968512 100644 (file)
@@ -49,6 +49,7 @@ export type CommonOptions = {
   inactivityTimeout: number
   poster: string
   startTime: number | string
+  stopTime: number | string
 
   theaterMode: boolean
   captions: boolean
@@ -116,11 +117,16 @@ export class PeertubePlayerManager {
       videojs(options.common.playerElement, videojsOptions, function (this: any) {
         const player = this
 
-        player.tech_.on('error', () => {
-          // Fallback to webtorrent?
-          if (mode === 'p2p-media-loader') {
-            self.fallbackToWebTorrent(player, options)
-          }
+        let alreadyFallback = false
+
+        player.tech_.one('error', () => {
+          if (!alreadyFallback) self.maybeFallbackToWebTorrent(mode, player, options)
+          alreadyFallback = true
+        })
+
+        player.one('error', () => {
+          if (!alreadyFallback) self.maybeFallbackToWebTorrent(mode, player, options)
+          alreadyFallback = true
         })
 
         self.addContextMenu(mode, player, options.common.embedUrl)
@@ -130,12 +136,19 @@ export class PeertubePlayerManager {
     })
   }
 
-  private static async fallbackToWebTorrent (player: any, options: PeertubePlayerManagerOptions) {
+  private static async maybeFallbackToWebTorrent (currentMode: PlayerMode, player: any, options: PeertubePlayerManagerOptions) {
+    if (currentMode === 'webtorrent') return
+
+    console.log('Fallback to webtorrent.')
+
     const newVideoElement = document.createElement('video')
     newVideoElement.className = this.playerElementClassName
 
     // VideoJS wraps our video element inside a div
-    const currentParentPlayerElement = options.common.playerElement.parentNode
+    let currentParentPlayerElement = options.common.playerElement.parentNode
+    // Fix on IOS, don't ask me why
+    if (!currentParentPlayerElement) currentParentPlayerElement = document.getElementById(options.common.playerElement.id).parentNode
+
     currentParentPlayerElement.parentNode.insertBefore(newVideoElement, currentParentPlayerElement)
 
     options.common.playerElement = newVideoElement
@@ -196,10 +209,10 @@ export class PeertubePlayerManager {
         autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
         videoViewUrl: commonOptions.videoViewUrl,
         videoDuration: commonOptions.videoDuration,
-        startTime: commonOptions.startTime,
         userWatching: commonOptions.userWatching,
         subtitle: commonOptions.subtitle,
-        videoCaptions: commonOptions.videoCaptions
+        videoCaptions: commonOptions.videoCaptions,
+        stopTime: commonOptions.stopTime
       }
     }
 
@@ -207,6 +220,7 @@ export class PeertubePlayerManager {
       const p2pMediaLoader: P2PMediaLoaderPluginOptions = {
         redundancyBaseUrls: options.p2pMediaLoader.redundancyBaseUrls,
         type: 'application/x-mpegURL',
+        startTime: commonOptions.startTime,
         src: p2pMediaLoaderOptions.playlistUrl
       }
 
@@ -251,7 +265,8 @@ export class PeertubePlayerManager {
         autoplay,
         videoDuration: commonOptions.videoDuration,
         playerElement: commonOptions.playerElement,
-        videoFiles: webtorrentOptions.videoFiles
+        videoFiles: webtorrentOptions.videoFiles,
+        startTime: commonOptions.startTime
       }
       Object.assign(plugins, { webtorrent })