+
+ private buildPlayerManagerOptions (params: {
+ video: VideoDetails,
+ videoCaptions: VideoCaption[],
+ urlOptions: CustomizationOptions & { playerMode: PlayerMode },
+ user?: AuthUser
+ }) {
+ const { video, videoCaptions, urlOptions, user } = params
+
+ let startTime = timeToInt(urlOptions.startTime) || (video.userHistory ? video.userHistory.currentTime : 0)
+ // If we are at the end of the video, reset the timer
+ if (video.duration - startTime <= 1) startTime = 0
+
+ const playerCaptions = videoCaptions.map(c => ({
+ label: c.language.label,
+ language: c.language.id,
+ src: environment.apiUrl + c.captionPath
+ }))
+
+ const options: PeertubePlayerManagerOptions = {
+ common: {
+ autoplay: this.isAutoplay(),
+
+ playerElement: this.playerElement,
+ onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
+
+ videoDuration: video.duration,
+ enableHotkeys: true,
+ inactivityTimeout: 2500,
+ poster: video.previewUrl,
+
+ startTime,
+ stopTime: urlOptions.stopTime,
+ controls: urlOptions.controls,
+ muted: urlOptions.muted,
+ loop: urlOptions.loop,
+ subtitle: urlOptions.subtitle,
+
+ peertubeLink: urlOptions.peertubeLink,
+
+ theaterButton: true,
+ captions: videoCaptions.length !== 0,
+
+ videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
+ ? this.videoService.getVideoViewUrl(video.uuid)
+ : null,
+ embedUrl: video.embedUrl,
+
+ language: this.localeId,
+
+ userWatching: user && user.videosHistoryEnabled === true ? {
+ url: this.videoService.getUserWatchingVideoUrl(video.uuid),
+ authorizationHeader: this.authService.getRequestHeaderValue()
+ } : undefined,
+
+ serverUrl: environment.apiUrl,
+
+ videoCaptions: playerCaptions
+ },
+
+ webtorrent: {
+ videoFiles: video.files
+ }
+ }
+
+ let mode: PlayerMode
+
+ if (urlOptions.playerMode) {
+ if (urlOptions.playerMode === 'p2p-media-loader') mode = 'p2p-media-loader'
+ else mode = 'webtorrent'
+ } else {
+ if (video.hasHlsPlaylist()) mode = 'p2p-media-loader'
+ else mode = 'webtorrent'
+ }
+
+ if (mode === 'p2p-media-loader') {
+ const hlsPlaylist = video.getHlsPlaylist()
+
+ const p2pMediaLoader = {
+ playlistUrl: hlsPlaylist.playlistUrl,
+ segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
+ redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
+ trackerAnnounce: video.trackerUrls,
+ videoFiles: hlsPlaylist.files
+ } as P2PMediaLoaderOptions
+
+ Object.assign(options, { p2pMediaLoader })
+ }
+
+ return { playerMode: mode, playerOptions: options }
+ }
+
+ private pausePlayer () {
+ if (!this.player) return
+
+ this.player.pause()
+ }
+
+ private initHotkeys () {
+ this.hotkeys = [
+ // These hotkeys are managed by the player
+ new Hotkey('f', e => e, undefined, this.i18n('Enter/exit fullscreen (requires player focus)')),
+ new Hotkey('space', e => e, undefined, this.i18n('Play/Pause the video (requires player focus)')),
+ new Hotkey('m', e => e, undefined, this.i18n('Mute/unmute the video (requires player focus)')),
+
+ new Hotkey('0-9', e => e, undefined, this.i18n('Skip to a percentage of the video: 0 is 0% and 9 is 90% (requires player focus)')),
+
+ new Hotkey('up', e => e, undefined, this.i18n('Increase the volume (requires player focus)')),
+ new Hotkey('down', e => e, undefined, this.i18n('Decrease the volume (requires player focus)')),
+
+ new Hotkey('right', e => e, undefined, this.i18n('Seek the video forward (requires player focus)')),
+ new Hotkey('left', e => e, undefined, this.i18n('Seek the video backward (requires player focus)')),
+
+ new Hotkey('>', e => e, undefined, this.i18n('Increase playback rate (requires player focus)')),
+ new Hotkey('<', e => e, undefined, this.i18n('Decrease playback rate (requires player focus)')),
+
+ new Hotkey('.', e => e, undefined, this.i18n('Navigate in the video frame by frame (requires player focus)'))
+ ]
+
+ if (this.isUserLoggedIn()) {
+ this.hotkeys = this.hotkeys.concat([
+ new Hotkey('shift+l', () => {
+ this.setLike()
+ return false
+ }, undefined, this.i18n('Like the video')),
+
+ new Hotkey('shift+d', () => {
+ this.setDislike()
+ return false
+ }, undefined, this.i18n('Dislike the video')),
+
+ new Hotkey('shift+s', () => {
+ this.subscribeButton.subscribed ? this.subscribeButton.unsubscribe() : this.subscribeButton.subscribe()
+ return false
+ }, undefined, this.i18n('Subscribe to the account'))
+ ])
+ }
+
+ this.hotkeysService.add(this.hotkeys)
+ }