aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-07 17:06:00 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commitf0a3988066f72a28bb44520af072f18d91d77dde (patch)
treedfa3a92102557b567530c5dd014c90866621140a /client/src/assets/player
parent830b4faff15fb9c81d88e8e69fcdf94aad32bef8 (diff)
downloadPeerTube-f0a3988066f72a28bb44520af072f18d91d77dde.tar.gz
PeerTube-f0a3988066f72a28bb44520af072f18d91d77dde.tar.zst
PeerTube-f0a3988066f72a28bb44520af072f18d91d77dde.zip
Add to playlist dropdown
Diffstat (limited to 'client/src/assets/player')
-rw-r--r--client/src/assets/player/peertube-player-manager.ts9
-rw-r--r--client/src/assets/player/peertube-plugin.ts16
-rw-r--r--client/src/assets/player/peertube-videojs-typings.ts7
-rw-r--r--client/src/assets/player/utils.ts20
-rw-r--r--client/src/assets/player/webtorrent/webtorrent-plugin.ts4
5 files changed, 39 insertions, 17 deletions
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts
index 7631d095f..6cdd54372 100644
--- a/client/src/assets/player/peertube-player-manager.ts
+++ b/client/src/assets/player/peertube-player-manager.ts
@@ -49,6 +49,7 @@ export type CommonOptions = {
49 inactivityTimeout: number 49 inactivityTimeout: number
50 poster: string 50 poster: string
51 startTime: number | string 51 startTime: number | string
52 stopTime: number | string
52 53
53 theaterMode: boolean 54 theaterMode: boolean
54 captions: boolean 55 captions: boolean
@@ -199,10 +200,10 @@ export class PeertubePlayerManager {
199 autoplay, // Use peertube plugin autoplay because we get the file by webtorrent 200 autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
200 videoViewUrl: commonOptions.videoViewUrl, 201 videoViewUrl: commonOptions.videoViewUrl,
201 videoDuration: commonOptions.videoDuration, 202 videoDuration: commonOptions.videoDuration,
202 startTime: commonOptions.startTime,
203 userWatching: commonOptions.userWatching, 203 userWatching: commonOptions.userWatching,
204 subtitle: commonOptions.subtitle, 204 subtitle: commonOptions.subtitle,
205 videoCaptions: commonOptions.videoCaptions 205 videoCaptions: commonOptions.videoCaptions,
206 stopTime: commonOptions.stopTime
206 } 207 }
207 } 208 }
208 209
@@ -210,6 +211,7 @@ export class PeertubePlayerManager {
210 const p2pMediaLoader: P2PMediaLoaderPluginOptions = { 211 const p2pMediaLoader: P2PMediaLoaderPluginOptions = {
211 redundancyBaseUrls: options.p2pMediaLoader.redundancyBaseUrls, 212 redundancyBaseUrls: options.p2pMediaLoader.redundancyBaseUrls,
212 type: 'application/x-mpegURL', 213 type: 'application/x-mpegURL',
214 startTime: commonOptions.startTime,
213 src: p2pMediaLoaderOptions.playlistUrl 215 src: p2pMediaLoaderOptions.playlistUrl
214 } 216 }
215 217
@@ -254,7 +256,8 @@ export class PeertubePlayerManager {
254 autoplay, 256 autoplay,
255 videoDuration: commonOptions.videoDuration, 257 videoDuration: commonOptions.videoDuration,
256 playerElement: commonOptions.playerElement, 258 playerElement: commonOptions.playerElement,
257 videoFiles: webtorrentOptions.videoFiles 259 videoFiles: webtorrentOptions.videoFiles,
260 startTime: commonOptions.startTime
258 } 261 }
259 Object.assign(plugins, { webtorrent }) 262 Object.assign(plugins, { webtorrent })
260 263
diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts
index 92ac57cf5..3991e4627 100644
--- a/client/src/assets/player/peertube-plugin.ts
+++ b/client/src/assets/player/peertube-plugin.ts
@@ -22,7 +22,6 @@ import {
22 22
23const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') 23const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin')
24class PeerTubePlugin extends Plugin { 24class PeerTubePlugin extends Plugin {
25 private readonly startTime: number = 0
26 private readonly videoViewUrl: string 25 private readonly videoViewUrl: string
27 private readonly videoDuration: number 26 private readonly videoDuration: number
28 private readonly CONSTANTS = { 27 private readonly CONSTANTS = {
@@ -35,13 +34,11 @@ class PeerTubePlugin extends Plugin {
35 34
36 private videoViewInterval: any 35 private videoViewInterval: any
37 private userWatchingVideoInterval: any 36 private userWatchingVideoInterval: any
38 private qualityObservationTimer: any
39 private lastResolutionChange: ResolutionUpdateData 37 private lastResolutionChange: ResolutionUpdateData
40 38
41 constructor (player: videojs.Player, options: PeerTubePluginOptions) { 39 constructor (player: videojs.Player, options: PeerTubePluginOptions) {
42 super(player, options) 40 super(player, options)
43 41
44 this.startTime = timeToInt(options.startTime)
45 this.videoViewUrl = options.videoViewUrl 42 this.videoViewUrl = options.videoViewUrl
46 this.videoDuration = options.videoDuration 43 this.videoDuration = options.videoDuration
47 this.videoCaptions = options.videoCaptions 44 this.videoCaptions = options.videoCaptions
@@ -84,6 +81,14 @@ class PeerTubePlugin extends Plugin {
84 saveMuteInStore(this.player.muted()) 81 saveMuteInStore(this.player.muted())
85 }) 82 })
86 83
84 if (options.stopTime) {
85 const stopTime = timeToInt(options.stopTime)
86
87 this.player.on('timeupdate', () => {
88 if (this.player.currentTime() > stopTime) this.player.pause()
89 })
90 }
91
87 this.player.textTracks().on('change', () => { 92 this.player.textTracks().on('change', () => {
88 const showing = this.player.textTracks().tracks_.find((t: { kind: string, mode: string }) => { 93 const showing = this.player.textTracks().tracks_.find((t: { kind: string, mode: string }) => {
89 return t.kind === 'captions' && t.mode === 'showing' 94 return t.kind === 'captions' && t.mode === 'showing'
@@ -109,10 +114,7 @@ class PeerTubePlugin extends Plugin {
109 } 114 }
110 115
111 dispose () { 116 dispose () {
112 clearTimeout(this.qualityObservationTimer) 117 if (this.videoViewInterval) clearInterval(this.videoViewInterval)
113
114 clearInterval(this.videoViewInterval)
115
116 if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval) 118 if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval)
117 } 119 }
118 120
diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts
index 79a5a6c4d..a96b0bc8c 100644
--- a/client/src/assets/player/peertube-videojs-typings.ts
+++ b/client/src/assets/player/peertube-videojs-typings.ts
@@ -41,12 +41,13 @@ type PeerTubePluginOptions = {
41 autoplay: boolean 41 autoplay: boolean
42 videoViewUrl: string 42 videoViewUrl: string
43 videoDuration: number 43 videoDuration: number
44 startTime: number | string
45 44
46 userWatching?: UserWatching 45 userWatching?: UserWatching
47 subtitle?: string 46 subtitle?: string
48 47
49 videoCaptions: VideoJSCaption[] 48 videoCaptions: VideoJSCaption[]
49
50 stopTime: number | string
50} 51}
51 52
52type WebtorrentPluginOptions = { 53type WebtorrentPluginOptions = {
@@ -56,12 +57,16 @@ type WebtorrentPluginOptions = {
56 videoDuration: number 57 videoDuration: number
57 58
58 videoFiles: VideoFile[] 59 videoFiles: VideoFile[]
60
61 startTime: number | string
59} 62}
60 63
61type P2PMediaLoaderPluginOptions = { 64type P2PMediaLoaderPluginOptions = {
62 redundancyBaseUrls: string[] 65 redundancyBaseUrls: string[]
63 type: string 66 type: string
64 src: string 67 src: string
68
69 startTime: number | string
65} 70}
66 71
67type VideoJSPluginOptions = { 72type VideoJSPluginOptions = {
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts
index 8d87567c2..54f131310 100644
--- a/client/src/assets/player/utils.ts
+++ b/client/src/assets/player/utils.ts
@@ -42,7 +42,7 @@ function timeToInt (time: number | string) {
42 if (!time) return 0 42 if (!time) return 0
43 if (typeof time === 'number') return time 43 if (typeof time === 'number') return time
44 44
45 const reg = /^((\d+)h)?((\d+)m)?((\d+)s?)?$/ 45 const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/
46 const matches = time.match(reg) 46 const matches = time.match(reg)
47 47
48 if (!matches) return 0 48 if (!matches) return 0
@@ -54,18 +54,27 @@ function timeToInt (time: number | string) {
54 return hours * 3600 + minutes * 60 + seconds 54 return hours * 3600 + minutes * 60 + seconds
55} 55}
56 56
57function secondsToTime (seconds: number) { 57function secondsToTime (seconds: number, full = false, symbol?: string) {
58 let time = '' 58 let time = ''
59 59
60 const hourSymbol = (symbol || 'h')
61 const minuteSymbol = (symbol || 'm')
62 const secondsSymbol = full ? '' : 's'
63
60 let hours = Math.floor(seconds / 3600) 64 let hours = Math.floor(seconds / 3600)
61 if (hours >= 1) time = hours + 'h' 65 if (hours >= 1) time = hours + hourSymbol
66 else if (full) time = '0' + hourSymbol
62 67
63 seconds %= 3600 68 seconds %= 3600
64 let minutes = Math.floor(seconds / 60) 69 let minutes = Math.floor(seconds / 60)
65 if (minutes >= 1) time += minutes + 'm' 70 if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol
71 else if (minutes >= 1) time += minutes + minuteSymbol
72 else if (full) time += '00' + minuteSymbol
66 73
67 seconds %= 60 74 seconds %= 60
68 if (seconds >= 1) time += seconds + 's' 75 if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol
76 else if (seconds >= 1) time += seconds + secondsSymbol
77 else if (full) time += '00'
69 78
70 return time 79 return time
71} 80}
@@ -131,6 +140,7 @@ export {
131 getRtcConfig, 140 getRtcConfig,
132 toTitleCase, 141 toTitleCase,
133 timeToInt, 142 timeToInt,
143 secondsToTime,
134 buildVideoLink, 144 buildVideoLink,
135 buildVideoEmbed, 145 buildVideoEmbed,
136 videoFileMaxByResolution, 146 videoFileMaxByResolution,
diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
index c69bf31fa..c7182acc9 100644
--- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts
+++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
@@ -6,7 +6,7 @@ import * as WebTorrent from 'webtorrent'
6import { VideoFile } from '../../../../../shared/models/videos/video.model' 6import { VideoFile } from '../../../../../shared/models/videos/video.model'
7import { renderVideo } from './video-renderer' 7import { renderVideo } from './video-renderer'
8import { LoadedQualityData, PlayerNetworkInfo, VideoJSComponentInterface, WebtorrentPluginOptions } from '../peertube-videojs-typings' 8import { LoadedQualityData, PlayerNetworkInfo, VideoJSComponentInterface, WebtorrentPluginOptions } from '../peertube-videojs-typings'
9import { getRtcConfig, videoFileMaxByResolution, videoFileMinByResolution } from '../utils' 9import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution } from '../utils'
10import { PeertubeChunkStore } from './peertube-chunk-store' 10import { PeertubeChunkStore } from './peertube-chunk-store'
11import { 11import {
12 getAverageBandwidthInStore, 12 getAverageBandwidthInStore,
@@ -73,6 +73,8 @@ class WebTorrentPlugin extends Plugin {
73 constructor (player: videojs.Player, options: WebtorrentPluginOptions) { 73 constructor (player: videojs.Player, options: WebtorrentPluginOptions) {
74 super(player, options) 74 super(player, options)
75 75
76 this.startTime = timeToInt(options.startTime)
77
76 // Disable auto play on iOS 78 // Disable auto play on iOS
77 this.autoplay = options.autoplay && this.isIOS() === false 79 this.autoplay = options.autoplay && this.isIOS() === false
78 this.playerRefusedP2P = !getStoredWebTorrentEnabled() 80 this.playerRefusedP2P = !getStoredWebTorrentEnabled()