]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/peertube-player.ts
Fix transcoding
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-player.ts
index 7e53d2142f9fb639c7148d821745b461ec1a86f4..ef9e7fcc06895998e22afbe10671ebb7c7edd8a2 100644 (file)
@@ -2,7 +2,6 @@ import { VideoFile } from '../../../../shared/models/videos'
 
 import 'videojs-hotkeys'
 import 'videojs-dock'
-import 'videojs-contextmenu'
 import 'videojs-contextmenu-ui'
 import './peertube-link-button'
 import './resolution-menu-button'
@@ -11,7 +10,7 @@ import './webtorrent-info-button'
 import './peertube-videojs-plugin'
 import './peertube-load-progress-bar'
 import './theater-button'
-import { VideoJSCaption, videojsUntyped } from './peertube-videojs-typings'
+import { UserWatching, VideoJSCaption, videojsUntyped } from './peertube-videojs-typings'
 import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils'
 import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n'
 
@@ -35,10 +34,13 @@ function getVideojsOptions (options: {
   startTime: number | string
   theaterMode: boolean,
   videoCaptions: VideoJSCaption[],
+
   language?: string,
   controls?: boolean,
   muted?: boolean,
   loop?: boolean
+
+  userWatching?: UserWatching
 }) {
   const videojsOptions = {
     // We don't use text track settings for now
@@ -49,7 +51,7 @@ function getVideojsOptions (options: {
     poster: options.poster,
     autoplay: false,
     inactivityTimeout: options.inactivityTimeout,
-    playbackRates: [ 0.5, 1, 1.5, 2 ],
+    playbackRates: [ 0.5, 0.75, 1, 1.25, 1.5, 2 ],
     plugins: {
       peertube: {
         autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
@@ -58,7 +60,8 @@ function getVideojsOptions (options: {
         playerElement: options.playerElement,
         videoViewUrl: options.videoViewUrl,
         videoDuration: options.videoDuration,
-        startTime: options.startTime
+        startTime: options.startTime,
+        userWatching: options.userWatching
       }
     },
     controlBar: {
@@ -70,7 +73,55 @@ function getVideojsOptions (options: {
     Object.assign(videojsOptions.plugins, {
       hotkeys: {
         enableVolumeScroll: false,
-        enableModifiersForNumbers: false
+        enableModifiersForNumbers: false,
+
+        fullscreenKey: function (event: any) {
+          // fullscreen with the f key or Ctrl+Enter
+          return event.key === 'f' || (event.ctrlKey && event.key === 'Enter')
+        },
+
+        seekStep: function (event: any) {
+          // mimic VLC seek behavior, and default to 5 (original value is 5).
+          if (event.ctrlKey && event.altKey) {
+            return 5 * 60
+          } else if (event.ctrlKey) {
+            return 60
+          } else if (event.altKey) {
+            return 10
+          } else {
+            return 5
+          }
+        },
+
+        customKeys: {
+          increasePlaybackRateKey: {
+            key: function (event: any) {
+              return event.key === '>'
+            },
+            handler: function (player: any) {
+              player.playbackRate((player.playbackRate() + 0.1).toFixed(2))
+            }
+          },
+          decreasePlaybackRateKey: {
+            key: function (event: any) {
+              return event.key === '<'
+            },
+            handler: function (player: any) {
+              player.playbackRate((player.playbackRate() - 0.1).toFixed(2))
+            }
+          },
+          frameByFrame: {
+            key: function (event: any) {
+              return event.key === '.'
+            },
+            handler: function (player: any) {
+              player.pause()
+              // Calculate movement distance (assuming 30 fps)
+              const dist = 1 / 30
+              player.currentTime(player.currentTime() + dist)
+            }
+          }
+        }
       }
     })
   }