]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Handle start at/stop at in playlist embed
authorChocobozzz <me@florianbigard.com>
Wed, 5 Aug 2020 09:57:38 +0000 (11:57 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Fri, 7 Aug 2020 06:58:29 +0000 (08:58 +0200)
client/src/assets/player/playlist/playlist-menu-item.ts
client/src/sass/player/playlist.scss
client/src/standalone/videos/embed.ts

index 21a7f80465f5b7d54c2e95163bb56f3ec301bcf5..87a72b6a360758c5ad4c609ed534fd8618366449 100644 (file)
@@ -1,6 +1,7 @@
 import videojs from 'video.js'
 import { VideoPlaylistElement } from '@shared/models'
 import { PlaylistItemOptions } from '../peertube-videojs-typings'
+import { secondsToTime } from '../utils'
 
 const Component = videojs.getComponent('Component')
 
@@ -61,6 +62,8 @@ class PlaylistMenuItem extends Component {
   }
 
   private buildAvailableVideo (li: HTMLElement, positionBlock: HTMLElement, options: PlaylistItemOptions) {
+    const videoElement = options.element
+
     const player = super.createEl('div', {
       className: 'item-player'
     })
@@ -68,7 +71,7 @@ class PlaylistMenuItem extends Component {
     positionBlock.appendChild(player)
 
     const thumbnail = super.createEl('img', {
-      src: window.location.origin + options.element.video.thumbnailPath
+      src: window.location.origin + videoElement.video.thumbnailPath
     })
 
     const infoBlock = super.createEl('div', {
@@ -76,18 +79,32 @@ class PlaylistMenuItem extends Component {
     })
 
     const title = super.createEl('div', {
-      innerHTML: options.element.video.name,
+      innerHTML: videoElement.video.name,
       className: 'title'
     })
 
     const channel = super.createEl('div', {
-      innerHTML: options.element.video.channel.displayName,
+      innerHTML: videoElement.video.channel.displayName,
       className: 'channel'
     })
 
     infoBlock.appendChild(title)
     infoBlock.appendChild(channel)
 
+    if (videoElement.startTimestamp || videoElement.stopTimestamp) {
+      let html = ''
+
+      if (videoElement.startTimestamp) html += secondsToTime(videoElement.startTimestamp)
+      if (videoElement.stopTimestamp) html += ' - ' + secondsToTime(videoElement.stopTimestamp)
+
+      const timestamps = super.createEl('div', {
+        innerHTML: html,
+        className: 'timestamps'
+      })
+
+      infoBlock.append(timestamps)
+    }
+
     li.append(thumbnail)
     li.append(infoBlock)
   }
index 544d45a481e00b9e082cabdd9363c769babf2558..d88baadebf98a7674a4adad9ffcd13745f80e523 100644 (file)
@@ -165,14 +165,20 @@ $playlist-menu-width: 350px;
       @include ellipsis;
 
       font-size: 13px;
-      margin-bottom: 5px;
+      margin-bottom: 3px;
     }
 
-    .channel {
+    .channel,
+    .timestamps {
       @include ellipsis;
 
       font-size: 11px;
       color: #bfbfbf;
     }
+
+    .timestamps {
+      font-size: 10px;
+      margin-top: 3px;
+    }
   }
 }
index 786d749a498903ca9181029fdb03dde864b1e111..f12b8c9ac9058180bcf69e08e433d7a09a36fae1 100644 (file)
@@ -441,11 +441,13 @@ export class PeerTubeEmbed {
         controls: this.controls,
         muted: this.muted,
         loop: this.loop,
+
         captions: videoCaptions.length !== 0,
-        startTime: this.startTime,
-        stopTime: this.stopTime,
         subtitle: this.subtitle,
 
+        startTime: this.playlist ? this.currentPlaylistElement.startTimestamp : this.startTime,
+        stopTime: this.playlist ? this.currentPlaylistElement.stopTimestamp : this.stopTime,
+
         nextVideo: this.playlist ? () => this.playNextVideo() : undefined,
         hasNextVideo: this.playlist ? () => !!this.getNextPlaylistElement() : undefined,
 
@@ -506,7 +508,12 @@ export class PeerTubeEmbed {
 
     if (this.isPlaylistEmbed()) {
       await this.buildPlaylistManager()
+
       this.player.playlist().updateSelected()
+
+      this.player.on('stopped', () => {
+        this.playNextVideo()
+      })
     }
   }