diff options
Diffstat (limited to 'client/src/assets/player')
-rw-r--r-- | client/src/assets/player/peertube-player.ts | 2 | ||||
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 8 | ||||
-rw-r--r-- | client/src/assets/player/peertube-videojs-typings.ts | 2 | ||||
-rw-r--r-- | client/src/assets/player/utils.ts | 44 |
4 files changed, 46 insertions, 10 deletions
diff --git a/client/src/assets/player/peertube-player.ts b/client/src/assets/player/peertube-player.ts index bf02ce91c..1fca6a7d2 100644 --- a/client/src/assets/player/peertube-player.ts +++ b/client/src/assets/player/peertube-player.ts | |||
@@ -32,7 +32,7 @@ function getVideojsOptions (options: { | |||
32 | inactivityTimeout: number, | 32 | inactivityTimeout: number, |
33 | peertubeLink: boolean, | 33 | peertubeLink: boolean, |
34 | poster: string, | 34 | poster: string, |
35 | startTime: number | 35 | startTime: number | string |
36 | theaterMode: boolean, | 36 | theaterMode: boolean, |
37 | videoCaptions: VideoJSCaption[], | 37 | videoCaptions: VideoJSCaption[], |
38 | controls?: boolean, | 38 | controls?: boolean, |
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 3f6fc4cc6..0dcbe49b1 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts | |||
@@ -4,7 +4,7 @@ import { VideoFile } from '../../../../shared/models/videos/video.model' | |||
4 | import { renderVideo } from './video-renderer' | 4 | import { renderVideo } from './video-renderer' |
5 | import './settings-menu-button' | 5 | import './settings-menu-button' |
6 | import { PeertubePluginOptions, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 6 | import { PeertubePluginOptions, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
7 | import { isMobile, videoFileMaxByResolution, videoFileMinByResolution } from './utils' | 7 | import { isMobile, videoFileMaxByResolution, videoFileMinByResolution, timeToInt } from './utils' |
8 | import * as CacheChunkStore from 'cache-chunk-store' | 8 | import * as CacheChunkStore from 'cache-chunk-store' |
9 | import { PeertubeChunkStore } from './peertube-chunk-store' | 9 | import { PeertubeChunkStore } from './peertube-chunk-store' |
10 | import { | 10 | import { |
@@ -76,7 +76,7 @@ class PeerTubePlugin extends Plugin { | |||
76 | // Disable auto play on iOS | 76 | // Disable auto play on iOS |
77 | this.autoplay = options.autoplay && this.isIOS() === false | 77 | this.autoplay = options.autoplay && this.isIOS() === false |
78 | 78 | ||
79 | this.startTime = options.startTime | 79 | this.startTime = timeToInt(options.startTime) |
80 | this.videoFiles = options.videoFiles | 80 | this.videoFiles = options.videoFiles |
81 | this.videoViewUrl = options.videoViewUrl | 81 | this.videoViewUrl = options.videoViewUrl |
82 | this.videoDuration = options.videoDuration | 82 | this.videoDuration = options.videoDuration |
@@ -264,8 +264,8 @@ class PeerTubePlugin extends Plugin { | |||
264 | // Magnet hash is not up to date with the torrent file, add directly the torrent file | 264 | // Magnet hash is not up to date with the torrent file, add directly the torrent file |
265 | if (err.message.indexOf('incorrect info hash') !== -1) { | 265 | if (err.message.indexOf('incorrect info hash') !== -1) { |
266 | console.error('Incorrect info hash detected, falling back to torrent file.') | 266 | console.error('Incorrect info hash detected, falling back to torrent file.') |
267 | const options = { forcePlay: true } | 267 | const newOptions = { forcePlay: true, seek: options.seek } |
268 | return this.addTorrent(this.torrent['xs'], previousVideoFile, options, done) | 268 | return this.addTorrent(this.torrent['xs'], previousVideoFile, newOptions, done) |
269 | } | 269 | } |
270 | 270 | ||
271 | return console.warn(err) | 271 | return console.warn(err) |
diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts index 9c0299237..993d5ee6b 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/peertube-videojs-typings.ts | |||
@@ -27,7 +27,7 @@ type PeertubePluginOptions = { | |||
27 | playerElement: HTMLVideoElement | 27 | playerElement: HTMLVideoElement |
28 | videoViewUrl: string | 28 | videoViewUrl: string |
29 | videoDuration: number | 29 | videoDuration: number |
30 | startTime: number | 30 | startTime: number | string |
31 | autoplay: boolean, | 31 | autoplay: boolean, |
32 | videoCaptions: VideoJSCaption[] | 32 | videoCaptions: VideoJSCaption[] |
33 | } | 33 | } |
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index c27e630e5..c02e19929 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -24,15 +24,50 @@ function isMobile () { | |||
24 | } | 24 | } |
25 | 25 | ||
26 | function buildVideoLink (time?: number) { | 26 | function buildVideoLink (time?: number) { |
27 | let href = window.location.href.replace('/embed/', '/watch/') | 27 | const baseEmbedPath = window.location.pathname.replace('/embed/', '/watch/') |
28 | const baseEmbedURL = window.location.origin + baseEmbedPath | ||
29 | |||
28 | if (time) { | 30 | if (time) { |
29 | const timeInt = Math.floor(time) | 31 | const timeInt = Math.floor(time) |
30 | 32 | ||
31 | if (window.location.search) href += '&start=' + timeInt | 33 | const params = new URLSearchParams(window.location.search) |
32 | else href += '?start=' + timeInt | 34 | params.set('start', secondsToTime(timeInt)) |
35 | |||
36 | return baseEmbedURL + '?' + params.toString() | ||
33 | } | 37 | } |
34 | 38 | ||
35 | return href | 39 | return baseEmbedURL |
40 | } | ||
41 | |||
42 | function timeToInt (time: number | string) { | ||
43 | if (typeof time === 'number') return time | ||
44 | |||
45 | const reg = /^((\d+)h)?((\d+)m)?((\d+)s?)?$/ | ||
46 | const matches = time.match(reg) | ||
47 | |||
48 | if (!matches) return 0 | ||
49 | |||
50 | const hours = parseInt(matches[2] || '0', 10) | ||
51 | const minutes = parseInt(matches[4] || '0', 10) | ||
52 | const seconds = parseInt(matches[6] || '0', 10) | ||
53 | |||
54 | return hours * 3600 + minutes * 60 + seconds | ||
55 | } | ||
56 | |||
57 | function secondsToTime (seconds: number) { | ||
58 | let time = '' | ||
59 | |||
60 | let hours = Math.floor(seconds / 3600) | ||
61 | if (hours >= 1) time = hours + 'h' | ||
62 | |||
63 | seconds %= 3600 | ||
64 | let minutes = Math.floor(seconds / 60) | ||
65 | if (minutes >= 1) time += minutes + 'm' | ||
66 | |||
67 | seconds %= 60 | ||
68 | if (seconds >= 1) time += seconds + 's' | ||
69 | |||
70 | return time | ||
36 | } | 71 | } |
37 | 72 | ||
38 | function buildVideoEmbed (embedUrl: string) { | 73 | function buildVideoEmbed (embedUrl: string) { |
@@ -81,6 +116,7 @@ function videoFileMinByResolution (files: VideoFile[]) { | |||
81 | 116 | ||
82 | export { | 117 | export { |
83 | toTitleCase, | 118 | toTitleCase, |
119 | timeToInt, | ||
84 | buildVideoLink, | 120 | buildVideoLink, |
85 | buildVideoEmbed, | 121 | buildVideoEmbed, |
86 | videoFileMaxByResolution, | 122 | videoFileMaxByResolution, |