From a472cf033003cf96b69a80808b2dce1fe382e09b Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 11 Apr 2021 11:00:32 +0200 Subject: add loop toggle to the player contextmenu --- .../src/assets/player/peertube-player-manager.ts | 65 +++++++++++++--------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'client/src/assets') diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 119dec379..018845a54 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -1,6 +1,6 @@ import 'videojs-hotkeys/videojs.hotkeys' import 'videojs-dock' -import 'videojs-contextmenu-ui' +import 'videojs-contextmenu-pt' import 'videojs-contrib-quality-levels' import './upnext/end-card' import './upnext/upnext-plugin' @@ -122,7 +122,6 @@ export type PeertubePlayerManagerOptions = { export class PeertubePlayerManager { private static playerElementClassName: string private static onPlayerChange: (player: videojs.Player) => void - private static alreadyPlayed = false static initState () { @@ -497,36 +496,48 @@ export class PeertubePlayerManager { } private static addContextMenu (mode: PlayerMode, player: videojs.Player, videoEmbedUrl: string, videoEmbedTitle: string) { - const content = [ - { - label: player.localize('Copy the video URL'), - listener: function () { - copyToClipboard(buildVideoLink()) - } - }, - { - label: player.localize('Copy the video URL at the current time'), - listener: function (this: videojs.Player) { - copyToClipboard(buildVideoLink({ startTime: this.currentTime() })) - } - }, - { - label: player.localize('Copy embed code'), - listener: () => { - copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle)) + const content = () => { + const isLoopEnabled = player.options_['loop'] + const items = [ + { + label: isLoopEnabled ? player.localize('Stop playing in loop') : player.localize('Play in loop'), + listener: function () { + player.options_['loop'] = !isLoopEnabled + } + }, + { + label: player.localize('Copy the video URL'), + listener: function () { + copyToClipboard(buildVideoLink()) + } + }, + { + label: player.localize('Copy the video URL at the current time'), + listener: function (this: videojs.Player) { + copyToClipboard(buildVideoLink({ startTime: this.currentTime() })) + } + }, + { + label: player.localize('Copy embed code'), + listener: () => { + copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle)) + } } + ] + + if (mode === 'webtorrent') { + items.push({ + label: player.localize('Copy magnet URI'), + listener: function (this: videojs.Player) { + copyToClipboard(this.webtorrent().getCurrentVideoFile().magnetUri) + } + }) } - ] - if (mode === 'webtorrent') { - content.push({ - label: player.localize('Copy magnet URI'), - listener: function (this: videojs.Player) { - copyToClipboard(this.webtorrent().getCurrentVideoFile().magnetUri) - } - }) + return items } + // adding the menu player.contextmenuUI({ content }) } -- cgit v1.2.3