Avoid always resuming the end of the video
This commit is contained in:
parent
c0687c91b9
commit
6de076222a
|
@ -91,6 +91,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
private hotkeys: Hotkey[] = []
|
private hotkeys: Hotkey[] = []
|
||||||
|
|
||||||
|
private static VIEW_VIDEO_INTERVAL_MS = 5000
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private elementRef: ElementRef,
|
private elementRef: ElementRef,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -613,16 +615,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
const byLocalStorage = getStoredVideoWatchHistory(video.uuid)
|
const byLocalStorage = getStoredVideoWatchHistory(video.uuid)
|
||||||
|
|
||||||
if (byUrl) return timeToInt(urlOptions.startTime)
|
if (byUrl) return timeToInt(urlOptions.startTime)
|
||||||
if (byHistory) return video.userHistory.currentTime
|
|
||||||
if (byLocalStorage) return byLocalStorage.duration
|
|
||||||
|
|
||||||
return 0
|
let startTime = 0
|
||||||
|
if (byHistory) startTime = video.userHistory.currentTime
|
||||||
|
if (byLocalStorage) startTime = byLocalStorage.duration
|
||||||
|
|
||||||
|
// If we are at the end of the video, reset the timer
|
||||||
|
if (video.duration - startTime <= 1) startTime = 0
|
||||||
|
|
||||||
|
return startTime
|
||||||
}
|
}
|
||||||
|
|
||||||
let startTime = getStartTime()
|
const startTime = getStartTime()
|
||||||
|
|
||||||
// If we are at the end of the video, reset the timer
|
|
||||||
if (video.duration - startTime <= 1) startTime = 0
|
|
||||||
|
|
||||||
const playerCaptions = videoCaptions.map(c => ({
|
const playerCaptions = videoCaptions.map(c => ({
|
||||||
label: c.language.label,
|
label: c.language.label,
|
||||||
|
@ -679,6 +683,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
|
videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
|
||||||
? this.videoService.getVideoViewUrl(video.uuid)
|
? this.videoService.getVideoViewUrl(video.uuid)
|
||||||
: null,
|
: null,
|
||||||
|
videoViewIntervalMs: VideoWatchComponent.VIEW_VIDEO_INTERVAL_MS,
|
||||||
authorizationHeader: () => this.authService.getRequestHeaderValue(),
|
authorizationHeader: () => this.authService.getRequestHeaderValue(),
|
||||||
|
|
||||||
serverUrl: environment.originServerUrl || window.location.origin,
|
serverUrl: environment.originServerUrl || window.location.origin,
|
||||||
|
|
|
@ -35,6 +35,7 @@ export class ManagerOptionsBuilder {
|
||||||
|
|
||||||
...pick(commonOptions, [
|
...pick(commonOptions, [
|
||||||
'videoViewUrl',
|
'videoViewUrl',
|
||||||
|
'videoViewIntervalMs',
|
||||||
'authorizationHeader',
|
'authorizationHeader',
|
||||||
'startTime',
|
'startTime',
|
||||||
'videoDuration',
|
'videoDuration',
|
||||||
|
|
|
@ -27,9 +27,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
private readonly videoUUID: string
|
private readonly videoUUID: string
|
||||||
private readonly startTime: number
|
private readonly startTime: number
|
||||||
|
|
||||||
private readonly CONSTANTS = {
|
private readonly videoViewIntervalMs: number
|
||||||
USER_VIEW_VIDEO_INTERVAL: 5000 // Every 5 seconds, notify the user is watching the video
|
|
||||||
}
|
|
||||||
|
|
||||||
private videoCaptions: VideoJSCaption[]
|
private videoCaptions: VideoJSCaption[]
|
||||||
private defaultSubtitle: string
|
private defaultSubtitle: string
|
||||||
|
@ -48,6 +46,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.authorizationHeader = options.authorizationHeader
|
this.authorizationHeader = options.authorizationHeader
|
||||||
this.videoUUID = options.videoUUID
|
this.videoUUID = options.videoUUID
|
||||||
this.startTime = timeToInt(options.startTime)
|
this.startTime = timeToInt(options.startTime)
|
||||||
|
this.videoViewIntervalMs = options.videoViewIntervalMs
|
||||||
|
|
||||||
this.videoCaptions = options.videoCaptions
|
this.videoCaptions = options.videoCaptions
|
||||||
this.initialInactivityTimeout = this.player.options_.inactivityTimeout
|
this.initialInactivityTimeout = this.player.options_.inactivityTimeout
|
||||||
|
@ -188,7 +187,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
})
|
})
|
||||||
|
|
||||||
this.player.one('ended', () => {
|
this.player.one('ended', () => {
|
||||||
const currentTime = Math.round(this.player.duration())
|
const currentTime = Math.floor(this.player.duration())
|
||||||
lastCurrentTime = currentTime
|
lastCurrentTime = currentTime
|
||||||
|
|
||||||
this.notifyUserIsWatching(currentTime, lastViewEvent)
|
this.notifyUserIsWatching(currentTime, lastViewEvent)
|
||||||
|
@ -197,7 +196,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
})
|
})
|
||||||
|
|
||||||
this.videoViewInterval = setInterval(() => {
|
this.videoViewInterval = setInterval(() => {
|
||||||
const currentTime = Math.round(this.player.currentTime())
|
const currentTime = Math.floor(this.player.currentTime())
|
||||||
|
|
||||||
// No need to update
|
// No need to update
|
||||||
if (currentTime === lastCurrentTime) return
|
if (currentTime === lastCurrentTime) return
|
||||||
|
@ -213,7 +212,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
if (!this.authorizationHeader()) {
|
if (!this.authorizationHeader()) {
|
||||||
saveVideoWatchHistory(this.videoUUID, currentTime)
|
saveVideoWatchHistory(this.videoUUID, currentTime)
|
||||||
}
|
}
|
||||||
}, this.CONSTANTS.USER_VIEW_VIDEO_INTERVAL)
|
}, this.videoViewIntervalMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
|
private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
|
||||||
|
|
|
@ -55,6 +55,8 @@ export interface CommonOptions extends CustomizationOptions {
|
||||||
inactivityTimeout: number
|
inactivityTimeout: number
|
||||||
poster: string
|
poster: string
|
||||||
|
|
||||||
|
videoViewIntervalMs: number
|
||||||
|
|
||||||
instanceName: string
|
instanceName: string
|
||||||
|
|
||||||
theaterButton: boolean
|
theaterButton: boolean
|
||||||
|
|
|
@ -108,6 +108,8 @@ type PeerTubePluginOptions = {
|
||||||
isLive: boolean
|
isLive: boolean
|
||||||
|
|
||||||
videoUUID: string
|
videoUUID: string
|
||||||
|
|
||||||
|
videoViewIntervalMs: number
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetricsPluginOptions = {
|
type MetricsPluginOptions = {
|
||||||
|
|
|
@ -217,6 +217,7 @@ export class PlayerManagerOptions {
|
||||||
videoCaptions,
|
videoCaptions,
|
||||||
inactivityTimeout: 2500,
|
inactivityTimeout: 2500,
|
||||||
videoViewUrl: this.videoFetcher.getVideoViewsUrl(video.uuid),
|
videoViewUrl: this.videoFetcher.getVideoViewsUrl(video.uuid),
|
||||||
|
videoViewIntervalMs: 5000,
|
||||||
metricsUrl: window.location.origin + '/api/v1/metrics/playback',
|
metricsUrl: window.location.origin + '/api/v1/metrics/playback',
|
||||||
|
|
||||||
videoShortUUID: video.shortUUID,
|
videoShortUUID: video.shortUUID,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user