+ const serverTranslations = await this.translationsPromise
+
+ if (videoResponse.status === 404) {
+ this.videoNotFound(serverTranslations)
+ return undefined
+ }
+
+ this.videoFetchError(serverTranslations)
+ return undefined
+ }
+
+ const captionsPromise = this.loadVideoCaptions(videoId)
+
+ return { captionsPromise, videoResponse }
+ }
+
+ private async buildPlaylistManager () {
+ const translations = await this.translationsPromise
+
+ this.player.upnext({
+ timeout: 10000, // 10s
+ headText: peertubeTranslate('Up Next', translations),
+ cancelText: peertubeTranslate('Cancel', translations),
+ suspendedText: peertubeTranslate('Autoplay is suspended', translations),
+ getTitle: () => this.nextVideoTitle(),
+ next: () => this.playNextVideo(),
+ condition: () => !!this.getNextPlaylistElement(),
+ suspended: () => false
+ })
+ }
+
+ private async playNextVideo () {
+ const next = this.getNextPlaylistElement()
+ if (!next) {
+ console.log('Next element not found in playlist.')
+ return
+ }
+
+ this.currentPlaylistElement = next
+
+ 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