From a950e4c82bd458e924b00698a77c06275a64a46c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Aug 2020 11:02:14 +0200 Subject: Add previous button --- client/src/standalone/videos/embed.ts | 39 ++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'client/src/standalone') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 17b0ee9ef..786d749a4 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -309,13 +309,13 @@ export class PeerTubeEmbed { cancelText: peertubeTranslate('Cancel', translations), suspendedText: peertubeTranslate('Autoplay is suspended', translations), getTitle: () => this.nextVideoTitle(), - next: () => this.autoplayNext(), + next: () => this.playNextVideo(), condition: () => !!this.getNextPlaylistElement(), suspended: () => false }) } - private async autoplayNext () { + private async playNextVideo () { const next = this.getNextPlaylistElement() if (!next) { console.log('Next element not found in playlist.') @@ -327,6 +327,18 @@ export class PeerTubeEmbed { return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid) } + private async playPreviousVideo () { + const previous = this.getPreviousPlaylistElement() + if (!previous) { + console.log('Previous element not found in playlist.') + return + } + + this.currentPlaylistElement = previous + + return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid) + } + private async loadVideoAndBuildPlayer (uuid: string) { const res = await this.loadVideo(uuid) if (res === undefined) return @@ -357,6 +369,22 @@ export class PeerTubeEmbed { return next } + private getPreviousPlaylistElement (position?: number): VideoPlaylistElement { + if (!position) position = this.currentPlaylistElement.position -1 + + if (position < 1) { + return undefined + } + + const prev = this.playlistElements.find(e => e.position === position) + + if (!prev || !prev.video) { + return this.getNextPlaylistElement(position - 1) + } + + return prev + } + private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise) { let alreadyHadPlayer = false @@ -418,7 +446,12 @@ export class PeerTubeEmbed { stopTime: this.stopTime, subtitle: this.subtitle, - nextVideo: () => this.autoplayNext(), + nextVideo: this.playlist ? () => this.playNextVideo() : undefined, + hasNextVideo: this.playlist ? () => !!this.getNextPlaylistElement() : undefined, + + previousVideo: this.playlist ? () => this.playPreviousVideo() : undefined, + hasPreviousVideo: this.playlist ? () => !!this.getPreviousPlaylistElement() : undefined, + playlist: playlistPlugin, videoCaptions, -- cgit v1.2.3