]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Added a "previous" button on player when watching playlist
authorPoslovitch <poslovitch@bentobox.world>
Sun, 18 Apr 2021 08:40:04 +0000 (08:40 +0000)
committerChocobozzz <chocobozzz@cpy.re>
Mon, 26 Apr 2021 08:54:02 +0000 (10:54 +0200)
Implements https://github.com/Chocobozzz/PeerTube/issues/3485

client/src/app/+videos/+video-watch/video-watch-playlist.component.ts
client/src/app/+videos/+video-watch/video-watch.component.ts

index d76d0bbd28717e313bde206d4c4051525fb64587..cc908b924ecacfa4e5cd3a57ffa04fe19410d58f 100644 (file)
@@ -137,6 +137,33 @@ export class VideoWatchPlaylistComponent {
     this.onPlaylistVideosNearOfBottom(position)
   }
 
+  findPreviousPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
+    if (this.currentPlaylistPosition <= 1) {
+      // we have reached the top of the playlist: either loop or stop
+      if (this.loopPlaylist) {
+        this.currentPlaylistPosition = position = this.playlistPagination.totalItems
+      } else {
+        return
+      }
+    }
+    const previous = this.playlistElements.find(e => e.position === position)
+
+    if (!previous || !previous.video) {
+      return this.findPreviousPlaylistVideo(position - 1)
+    }
+
+    return previous
+  }
+
+  navigateToPreviousPlaylistVideo () {
+    const previous = this.findPreviousPlaylistVideo(this.currentPlaylistPosition - 1)
+    if (!previous) return
+
+    const start = previous.startTimestamp
+    const stop = previous.stopTimestamp
+    this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } })
+  }
+
   findNextPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
     if (this.currentPlaylistPosition >= this.playlistPagination.totalItems) {
       // we have reached the end of the playlist: either loop or stop
index 366e9bb57ce5bb809b3a0332d2b610f651464d4f..1f24c898e31965054dfd54e2322ecbbb5d5a49b4 100644 (file)
@@ -799,6 +799,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
       common: {
         autoplay: this.isAutoplay(),
         nextVideo: () => this.zone.run(() => this.autoplayNext()),
+        previousVideo: () => this.zone.run(() => {
+          // FIXME: Only show if this is a playlist
+          if (this.playlist) this.zone.run(() => this.videoWatchPlaylist.navigateToPreviousPlaylistVideo())
+        }),
 
         playerElement: this.playerElement,
         onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,