]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix changing video we are watching
authorChocobozzz <florian.bigard@gmail.com>
Mon, 11 Dec 2017 10:20:54 +0000 (11:20 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 11 Dec 2017 10:20:54 +0000 (11:20 +0100)
client/src/app/videos/+video-watch/video-watch.component.ts
client/src/assets/player/peertube-videojs-plugin.ts

index d4e3ec014903c8b051ba6a0af72d0726f192ccdb..bec6932ae6edbab263896a95155c6613a9662a2f 100644 (file)
@@ -69,6 +69,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
       )
 
     this.paramsSub = this.route.params.subscribe(routeParams => {
+      if (this.videoPlayerLoaded) {
+        this.player.pause()
+      }
+
       let uuid = routeParams['uuid']
       this.videoService.getVideo(uuid).subscribe(
         video => this.onVideoFetched(video),
@@ -276,30 +280,35 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
           return this.router.navigate([ '/videos/list' ])
         }
 
-        this.playerElement = this.elementRef.nativeElement.querySelector('#video-element')
-
-        const videojsOptions = {
-          controls: true,
-          autoplay: true,
-          plugins: {
-            peertube: {
-              videoFiles: this.video.files,
-              playerElement: this.playerElement,
-              autoplay: true,
-              peerTubeLink: false
+        // Player was already loaded
+        if (this.videoPlayerLoaded !== true) {
+          this.playerElement = this.elementRef.nativeElement.querySelector('#video-element')
+
+          const videojsOptions = {
+            controls: true,
+            autoplay: true,
+            plugins: {
+              peertube: {
+                videoFiles: this.video.files,
+                playerElement: this.playerElement,
+                autoplay: true,
+                peerTubeLink: false
+              }
             }
           }
-        }
 
-        this.videoPlayerLoaded = true
+          this.videoPlayerLoaded = true
 
-        const self = this
-        videojs(this.playerElement, videojsOptions, function () {
-          self.player = this
-          this.on('customError', (event, data) => {
-            self.handleError(data.err)
+          const self = this
+          videojs(this.playerElement, videojsOptions, function () {
+            self.player = this
+            this.on('customError', (event, data) => {
+              self.handleError(data.err)
+            })
           })
-        })
+        } else {
+          (this.player as any).setVideoFiles(this.video.files)
+        }
 
         this.setVideoDescriptionHTML()
 
index 4ba37b7d92ebe195105a33184f09d634dac9677a..4898c1efe29dcac6d32da4cb3affb6fb5af1c221 100644 (file)
@@ -283,6 +283,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