- this.errorsSub.unsubscribe()
- }
-
- loadVideo () {
- // Reset the error
- this.error = false
- // We are loading the video
- this.loading = true
-
- console.log('Adding ' + this.video.getDefaultMagnetUri() + '.')
-
- // The callback might never return if there are network issues
- // So we create a timer to inform the user the load is abnormally long
- this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG)
-
- const torrent = this.webTorrentService.add(this.video.getDefaultMagnetUri(), torrent => {
- // Clear the error timer
- window.clearTimeout(this.errorTimer)
- // Maybe the error was fired by the timer, so reset it
- this.error = false
-
- // We are not loading the video anymore
- this.loading = false
-
- console.log('Added ' + this.video.getDefaultMagnetUri() + '.')
- torrent.files[0].renderTo(this.playerElement, (err) => {
- if (err) {
- this.notificationsService.error('Error', 'Cannot append the file in the video element.')
- console.error(err)
- }
-
- // Hack to "simulate" src link in video.js >= 6
- // If no, we can't play the video after pausing it
- // https://github.com/videojs/video.js/blob/master/src/js/player.js#L1633
- (this.player as any).src = () => true
-
- this.player.play()
- })
-
- this.runInProgress(torrent)
- })
-
- torrent.on('error', err => this.handleError(err))
- torrent.on('warning', err => this.handleError(err))