- observable.subscribe(
- res => {
- if (res === false) {
- return this.router.navigate([ '/videos/list' ])
- }
-
- this.playerElement = this.elementRef.nativeElement.querySelector('#video-container')
-
- const videojsOptions = {
- controls: true,
- autoplay: true,
- plugins: {
- peertube: {
- videoFiles: this.video.files,
- playerElement: this.playerElement,
- autoplay: true,
- peerTubeLink: false
- }
- }
- }
-
- const self = this
- videojs(this.playerElement, videojsOptions, function () {
- self.player = this
- this.on('customError', (event, data) => {
- self.handleError(data.err)
- })
-
- this.on('torrentInfo', (event, data) => {
- self.downloadSpeed = data.downloadSpeed
- self.numPeers = data.numPeers
- self.uploadSpeed = data.uploadSpeed
- })
- })
+ // Flush old player if needed
+ this.flushPlayer()
+
+ // Build video element, because videojs remove it on dispose
+ const playerElementWrapper = this.elementRef.nativeElement.querySelector('#video-element-wrapper')
+ this.playerElement = document.createElement('video')
+ this.playerElement.className = 'video-js vjs-peertube-skin'
+ this.playerElement.setAttribute('playsinline', 'true')
+ playerElementWrapper.appendChild(this.playerElement)
+
+ const playerCaptions = videoCaptions.map(c => ({
+ label: c.language.label,
+ language: c.language.id,
+ src: environment.apiUrl + c.captionPath
+ }))
+
+ const videojsOptions = getVideojsOptions({
+ autoplay: this.isAutoplay(),
+ inactivityTimeout: 2500,
+ videoFiles: this.video.files,
+ videoCaptions: playerCaptions,
+ playerElement: this.playerElement,
+ videoViewUrl: this.video.privacy.id !== VideoPrivacy.PRIVATE ? this.videoService.getVideoViewUrl(this.video.uuid) : null,
+ videoDuration: this.video.duration,
+ enableHotkeys: true,
+ peertubeLink: false,
+ poster: this.video.previewUrl,
+ startTime,
+ theaterMode: true
+ })
+
+ if (this.videojsLocaleLoaded === false) {
+ await loadLocale(environment.apiUrl, videojs, isOnDevLocale() ? getDevLocale() : this.localeId)
+ this.videojsLocaleLoaded = true
+ }
+
+ const self = this
+ this.zone.runOutsideAngular(async () => {
+ videojs(this.playerElement, videojsOptions, function () {
+ self.player = this
+ this.on('customError', (event, data) => self.handleError(data.err))
+
+ addContextMenu(self.player, self.video.embedUrl)
+ })
+ })
+
+ this.setVideoDescriptionHTML()
+ this.setVideoLikesBarTooltipText()
+
+ this.setOpenGraphTags()
+ this.checkUserRating()
+ }
+
+ private setRating (nextRating) {
+ let method
+ switch (nextRating) {
+ case 'like':
+ method = this.videoService.setVideoLike
+ break
+ case 'dislike':
+ method = this.videoService.setVideoDislike
+ break
+ case 'none':
+ method = this.videoService.unsetVideoLike
+ break
+ }
+
+ method.call(this.videoService, this.video.id)
+ .subscribe(
+ () => {
+ // Update the video like attribute
+ this.updateVideoRating(this.userRating, nextRating)
+ this.userRating = nextRating
+ },