Add ability to set a start time
This commit is contained in:
parent
7ee4a4af0b
commit
f37bad639b
|
@ -102,7 +102,11 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
if (this.video && this.video.uuid === uuid) return
|
if (this.video && this.video.uuid === uuid) return
|
||||||
|
|
||||||
this.videoService.getVideo(uuid).subscribe(
|
this.videoService.getVideo(uuid).subscribe(
|
||||||
video => this.onVideoFetched(video),
|
video => {
|
||||||
|
const startTime = this.route.snapshot.queryParams.start
|
||||||
|
this.onVideoFetched(video, startTime)
|
||||||
|
.catch(err => this.handleError(err))
|
||||||
|
},
|
||||||
|
|
||||||
error => {
|
error => {
|
||||||
this.videoNotFound = true
|
this.videoNotFound = true
|
||||||
|
@ -315,7 +319,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onVideoFetched (video: VideoDetails) {
|
private async onVideoFetched (video: VideoDetails, startTime = 0) {
|
||||||
this.video = video
|
this.video = video
|
||||||
|
|
||||||
// Re init attributes
|
// Re init attributes
|
||||||
|
@ -350,7 +354,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
videoDuration: this.video.duration,
|
videoDuration: this.video.duration,
|
||||||
enableHotkeys: true,
|
enableHotkeys: true,
|
||||||
peertubeLink: false,
|
peertubeLink: false,
|
||||||
poster: this.video.previewUrl
|
poster: this.video.previewUrl,
|
||||||
|
startTime
|
||||||
})
|
})
|
||||||
|
|
||||||
const self = this
|
const self = this
|
||||||
|
|
|
@ -21,7 +21,8 @@ function getVideojsOptions (options: {
|
||||||
enableHotkeys: boolean,
|
enableHotkeys: boolean,
|
||||||
inactivityTimeout: number,
|
inactivityTimeout: number,
|
||||||
peertubeLink: boolean,
|
peertubeLink: boolean,
|
||||||
poster: string
|
poster: string,
|
||||||
|
startTime: number
|
||||||
}) {
|
}) {
|
||||||
const videojsOptions = {
|
const videojsOptions = {
|
||||||
controls: true,
|
controls: true,
|
||||||
|
@ -34,7 +35,8 @@ function getVideojsOptions (options: {
|
||||||
videoFiles: options.videoFiles,
|
videoFiles: options.videoFiles,
|
||||||
playerElement: options.playerElement,
|
playerElement: options.playerElement,
|
||||||
videoViewUrl: options.videoViewUrl,
|
videoViewUrl: options.videoViewUrl,
|
||||||
videoDuration: options.videoDuration
|
videoDuration: options.videoDuration,
|
||||||
|
startTime: options.startTime
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
controlBar: {
|
controlBar: {
|
||||||
|
|
|
@ -36,6 +36,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
private readonly playerElement: HTMLVideoElement
|
private readonly playerElement: HTMLVideoElement
|
||||||
|
|
||||||
private readonly autoplay: boolean = false
|
private readonly autoplay: boolean = false
|
||||||
|
private readonly startTime: number = 0
|
||||||
private readonly savePlayerSrcFunction: Function
|
private readonly savePlayerSrcFunction: Function
|
||||||
private readonly videoFiles: VideoFile[]
|
private readonly videoFiles: VideoFile[]
|
||||||
private readonly videoViewUrl: string
|
private readonly videoViewUrl: string
|
||||||
|
@ -71,6 +72,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.autoplay = this.player.options_.autoplay
|
this.autoplay = this.player.options_.autoplay
|
||||||
this.player.options_.autoplay = false
|
this.player.options_.autoplay = false
|
||||||
|
|
||||||
|
this.startTime = options.startTime
|
||||||
this.videoFiles = options.videoFiles
|
this.videoFiles = options.videoFiles
|
||||||
this.videoViewUrl = options.videoViewUrl
|
this.videoViewUrl = options.videoViewUrl
|
||||||
this.videoDuration = options.videoDuration
|
this.videoDuration = options.videoDuration
|
||||||
|
@ -94,7 +96,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.runViewAdd()
|
this.runViewAdd()
|
||||||
|
|
||||||
this.player.one('play', () => {
|
this.player.one('play', () => {
|
||||||
// Don't run immediately scheduler, wait some seconds the TCP connections are maid
|
// Don't run immediately scheduler, wait some seconds the TCP connections are made
|
||||||
this.runAutoQualitySchedulerTimer = setTimeout(() => {
|
this.runAutoQualitySchedulerTimer = setTimeout(() => {
|
||||||
this.runAutoQualityScheduler()
|
this.runAutoQualityScheduler()
|
||||||
}, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
|
}, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
|
||||||
|
@ -234,10 +236,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId)
|
const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId)
|
||||||
this.updateVideoFile(newVideoFile, delay, () => {
|
this.updateVideoFile(newVideoFile, delay, () => this.seek(currentTime))
|
||||||
this.player.currentTime(currentTime)
|
|
||||||
this.player.handleTechSeeked_()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flushVideoFile (videoFile: VideoFile, destroyRenderer = true) {
|
flushVideoFile (videoFile: VideoFile, destroyRenderer = true) {
|
||||||
|
@ -263,6 +262,11 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.trigger('autoResolutionUpdate')
|
this.trigger('autoResolutionUpdate')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private seek (time: number) {
|
||||||
|
this.player.currentTime(time)
|
||||||
|
this.player.handleTechSeeked_()
|
||||||
|
}
|
||||||
|
|
||||||
private getAppropriateFile (averageDownloadSpeed?: number): VideoFile {
|
private getAppropriateFile (averageDownloadSpeed?: number): VideoFile {
|
||||||
if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined
|
if (this.videoFiles === undefined || this.videoFiles.length === 0) return undefined
|
||||||
if (this.videoFiles.length === 1) return this.videoFiles[0]
|
if (this.videoFiles.length === 1) return this.videoFiles[0]
|
||||||
|
@ -310,12 +314,18 @@ class PeerTubePlugin extends Plugin {
|
||||||
|
|
||||||
if (this.autoplay === true) {
|
if (this.autoplay === true) {
|
||||||
this.player.posterImage.hide()
|
this.player.posterImage.hide()
|
||||||
this.updateVideoFile(undefined, 0, () => this.player.play())
|
this.updateVideoFile(undefined, 0, () => {
|
||||||
|
this.seek(this.startTime)
|
||||||
|
this.player.play()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// Proxy first play
|
// Proxy first play
|
||||||
const oldPlay = this.player.play.bind(this.player)
|
const oldPlay = this.player.play.bind(this.player)
|
||||||
this.player.play = () => {
|
this.player.play = () => {
|
||||||
this.updateVideoFile(undefined, 0, () => oldPlay)
|
this.updateVideoFile(undefined, 0, () => {
|
||||||
|
this.seek(this.startTime)
|
||||||
|
oldPlay()
|
||||||
|
})
|
||||||
this.player.play = oldPlay
|
this.player.play = oldPlay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ type PeertubePluginOptions = {
|
||||||
playerElement: HTMLVideoElement
|
playerElement: HTMLVideoElement
|
||||||
videoViewUrl: string
|
videoViewUrl: string
|
||||||
videoDuration: number
|
videoDuration: number
|
||||||
|
startTime: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// videojs typings don't have some method we need
|
// videojs typings don't have some method we need
|
||||||
|
|
|
@ -23,10 +23,15 @@ loadVideoInfo(videoId)
|
||||||
|
|
||||||
const videoElement = document.getElementById(videoContainerId) as HTMLVideoElement
|
const videoElement = document.getElementById(videoContainerId) as HTMLVideoElement
|
||||||
let autoplay = false
|
let autoplay = false
|
||||||
|
let startTime = 0
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let params = new URL(window.location.toString()).searchParams
|
let params = new URL(window.location.toString()).searchParams
|
||||||
autoplay = params.has('autoplay') && (params.get('autoplay') === '1' || params.get('autoplay') === 'true')
|
autoplay = params.has('autoplay') && (params.get('autoplay') === '1' || params.get('autoplay') === 'true')
|
||||||
|
|
||||||
|
const startTimeParamString = params.get('start')
|
||||||
|
const startTimeParamNumber = parseInt(startTimeParamString, 10)
|
||||||
|
if (isNaN(startTimeParamNumber) === false) startTime = startTimeParamNumber
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Cannot get params from URL.', err)
|
console.error('Cannot get params from URL.', err)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +45,8 @@ loadVideoInfo(videoId)
|
||||||
videoDuration: videoInfo.duration,
|
videoDuration: videoInfo.duration,
|
||||||
enableHotkeys: true,
|
enableHotkeys: true,
|
||||||
peertubeLink: true,
|
peertubeLink: true,
|
||||||
poster: window.location.origin + videoInfo.previewPath
|
poster: window.location.origin + videoInfo.previewPath,
|
||||||
|
startTime
|
||||||
})
|
})
|
||||||
videojs(videoContainerId, videojsOptions, function () {
|
videojs(videoContainerId, videojsOptions, function () {
|
||||||
const player = this
|
const player = this
|
||||||
|
|
Loading…
Reference in New Issue
Block a user