X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bvideos%2F%2Bvideo-watch%2Fvideo-watch-playlist.component.ts;h=0a4d6bfd11c66d2dd6a9e0852a28a182b332e167;hb=b1ed448e948211a59ab110c9d4c7c2e82819645e;hp=d76d0bbd28717e313bde206d4c4051525fb64587;hpb=d142c7b9c01735ecebc3511072c0e722ce2edc1b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts index d76d0bbd2..0a4d6bfd1 100644 --- a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts @@ -118,6 +118,9 @@ export class VideoWatchPlaylistComponent { updatePlaylistIndex (position: number) { if (this.playlistElements.length === 0 || !position) return + // Handle the reverse index + if (position < 0) position = this.playlist.videosLength + position + 1 + for (const playlistElement of this.playlistElements) { // >= if the previous videos were not valid if (playlistElement.video && playlistElement.position >= position) { @@ -137,27 +140,41 @@ export class VideoWatchPlaylistComponent { this.onPlaylistVideosNearOfBottom(position) } - findNextPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement { - if (this.currentPlaylistPosition >= this.playlistPagination.totalItems) { - // we have reached the end of the playlist: either loop or stop - if (this.loopPlaylist) { - this.currentPlaylistPosition = position = 0 - } else { - return - } - } + navigateToPreviousPlaylistVideo () { + const previous = this.findPlaylistVideo(this.currentPlaylistPosition - 1, 'previous') + if (!previous) return - const next = this.playlistElements.find(e => e.position === position) + const start = previous.startTimestamp + const stop = previous.stopTimestamp + this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } }) + } + + findPlaylistVideo (position: number, type: 'previous' | 'next'): VideoPlaylistElement { + if ( + (type === 'next' && position > this.playlistPagination.totalItems) || + (type === 'previous' && position < 1) + ) { + // End of the playlist: end the recursion if we're not in the loop mode + if (!this.loopPlaylist) return - if (!next || !next.video) { - return this.findNextPlaylistVideo(position + 1) + // Loop mode + position = type === 'previous' + ? this.playlistPagination.totalItems + : 1 } - return next + const found = this.playlistElements.find(e => e.position === position) + if (found && found.video) return found + + const newPosition = type === 'previous' + ? position - 1 + : position + 1 + + return this.findPlaylistVideo(newPosition, type) } navigateToNextPlaylistVideo () { - const next = this.findNextPlaylistVideo(this.currentPlaylistPosition + 1) + const next = this.findPlaylistVideo(this.currentPlaylistPosition + 1, 'next') if (!next) return const start = next.startTimestamp