aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-05 11:02:14 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-07 08:58:29 +0200
commita950e4c82bd458e924b00698a77c06275a64a46c (patch)
tree11bdeecb8950e6854eee79205823bcbb1e5a437c /client/src/standalone/videos
parent4572c3d0d92f5b1b79b34dbe2c7b6557a8a5b7e4 (diff)
downloadPeerTube-a950e4c82bd458e924b00698a77c06275a64a46c.tar.gz
PeerTube-a950e4c82bd458e924b00698a77c06275a64a46c.tar.zst
PeerTube-a950e4c82bd458e924b00698a77c06275a64a46c.zip
Add previous button
Diffstat (limited to 'client/src/standalone/videos')
-rw-r--r--client/src/standalone/videos/embed.ts39
1 files changed, 36 insertions, 3 deletions
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 {
309 cancelText: peertubeTranslate('Cancel', translations), 309 cancelText: peertubeTranslate('Cancel', translations),
310 suspendedText: peertubeTranslate('Autoplay is suspended', translations), 310 suspendedText: peertubeTranslate('Autoplay is suspended', translations),
311 getTitle: () => this.nextVideoTitle(), 311 getTitle: () => this.nextVideoTitle(),
312 next: () => this.autoplayNext(), 312 next: () => this.playNextVideo(),
313 condition: () => !!this.getNextPlaylistElement(), 313 condition: () => !!this.getNextPlaylistElement(),
314 suspended: () => false 314 suspended: () => false
315 }) 315 })
316 } 316 }
317 317
318 private async autoplayNext () { 318 private async playNextVideo () {
319 const next = this.getNextPlaylistElement() 319 const next = this.getNextPlaylistElement()
320 if (!next) { 320 if (!next) {
321 console.log('Next element not found in playlist.') 321 console.log('Next element not found in playlist.')
@@ -327,6 +327,18 @@ export class PeerTubeEmbed {
327 return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid) 327 return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
328 } 328 }
329 329
330 private async playPreviousVideo () {
331 const previous = this.getPreviousPlaylistElement()
332 if (!previous) {
333 console.log('Previous element not found in playlist.')
334 return
335 }
336
337 this.currentPlaylistElement = previous
338
339 return this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
340 }
341
330 private async loadVideoAndBuildPlayer (uuid: string) { 342 private async loadVideoAndBuildPlayer (uuid: string) {
331 const res = await this.loadVideo(uuid) 343 const res = await this.loadVideo(uuid)
332 if (res === undefined) return 344 if (res === undefined) return
@@ -357,6 +369,22 @@ export class PeerTubeEmbed {
357 return next 369 return next
358 } 370 }
359 371
372 private getPreviousPlaylistElement (position?: number): VideoPlaylistElement {
373 if (!position) position = this.currentPlaylistElement.position -1
374
375 if (position < 1) {
376 return undefined
377 }
378
379 const prev = this.playlistElements.find(e => e.position === position)
380
381 if (!prev || !prev.video) {
382 return this.getNextPlaylistElement(position - 1)
383 }
384
385 return prev
386 }
387
360 private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise<Response>) { 388 private async buildVideoPlayer (videoResponse: Response, captionsPromise: Promise<Response>) {
361 let alreadyHadPlayer = false 389 let alreadyHadPlayer = false
362 390
@@ -418,7 +446,12 @@ export class PeerTubeEmbed {
418 stopTime: this.stopTime, 446 stopTime: this.stopTime,
419 subtitle: this.subtitle, 447 subtitle: this.subtitle,
420 448
421 nextVideo: () => this.autoplayNext(), 449 nextVideo: this.playlist ? () => this.playNextVideo() : undefined,
450 hasNextVideo: this.playlist ? () => !!this.getNextPlaylistElement() : undefined,
451
452 previousVideo: this.playlist ? () => this.playPreviousVideo() : undefined,
453 hasPreviousVideo: this.playlist ? () => !!this.getPreviousPlaylistElement() : undefined,
454
422 playlist: playlistPlugin, 455 playlist: playlistPlugin,
423 456
424 videoCaptions, 457 videoCaptions,