videoFiles: this.video.files,
playerElement: this.playerElement,
peerTubeLink: false,
- videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid)
+ videoViewUrl: this.videoService.getVideoViewUrl(this.video.uuid),
+ videoDuration: this.video.duration
},
hotkeys: {
enableVolumeScroll: false
})
})
} else {
- this.player.peertube().setVideoFiles(this.video.files, this.videoService.getVideoViewUrl(this.video.uuid))
+ const videoViewUrl = this.videoService.getVideoViewUrl(this.video.uuid)
+ this.player.peertube().setVideoFiles(this.video.files, videoViewUrl, this.video.duration)
}
this.setVideoDescriptionHTML()
playerElement: HTMLVideoElement
peerTubeLink: boolean
videoViewUrl: string
+ videoDuration: number
}
// https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
private torrent: WebTorrent.Torrent
private autoplay = false
private videoViewUrl: string
+ private videoDuration: number
private videoViewInterval
+ private torrentInfoInterval
constructor (player: videojs.Player, options: PeertubePluginOptions) {
super(player, options)
this.videoFiles = options.videoFiles
this.videoViewUrl = options.videoViewUrl
+ this.videoDuration = options.videoDuration
// Hack to "simulate" src link in video.js >= 6
// Without this, we can't play the video after pausing it
this.player.ready(() => {
this.initializePlayer(options)
this.runTorrentInfoScheduler()
- this.prepareRunViewAdd()
+ this.runViewAdd()
})
}
dispose () {
+ clearInterval(this.videoViewInterval)
+ clearInterval(this.torrentInfoInterval)
+
// Don't need to destroy renderer, video player will be destroyed
this.flushVideoFile(this.currentVideoFile, false)
}
if (err) return this.handleError(err)
this.renderer = renderer
- if (!this.player.paused()) this.player.play().then(done)
- else done()
+ if (!this.player.paused()) {
+ const playPromise = this.player.play()
+ if (playPromise !== undefined) return playPromise.then(done)
+
+ return done()
+ }
+
+ return done()
})
})
}
}
- setVideoFiles (files: VideoFile[], videoViewUrl: string) {
+ setVideoFiles (files: VideoFile[], videoViewUrl: string, videoDuration: number) {
this.videoViewUrl = videoViewUrl
+ this.videoDuration = videoDuration
this.videoFiles = files
// Re run view add for the new video
- this.prepareRunViewAdd()
+ this.runViewAdd()
this.updateVideoFile(undefined, () => this.player.play())
}
}
private runTorrentInfoScheduler () {
- setInterval(() => {
+ this.torrentInfoInterval = setInterval(() => {
if (this.torrent !== undefined) {
this.trigger('torrentInfo', {
downloadSpeed: this.torrent.downloadSpeed,
}, 1000)
}
- private prepareRunViewAdd () {
- if (this.player.readyState() < 1) {
- return this.player.one('loadedmetadata', () => this.runViewAdd())
- }
-
- this.runViewAdd()
- }
-
private runViewAdd () {
this.clearVideoViewInterval()
// After 30 seconds (or 3/4 of the video), add a view to the video
let minSecondsToView = 30
- const duration = this.player.duration()
- if (duration < minSecondsToView) minSecondsToView = (duration * 3) / 4
+ if (this.videoDuration < minSecondsToView) minSecondsToView = (this.videoDuration * 3) / 4
let secondsViewed = 0
this.videoViewInterval = setInterval(() => {