- const self = this
- this.zone.runOutsideAngular(() => {
- videojs(this.playerElement, videojsOptions, function () {
- self.player = this
- this.on('customError', (event, data) => self.handleError(data.err))
+ webtorrent: {
+ videoFiles: this.video.files
+ }
+ }
+
+ const mode: PlayerMode = urlOptions.playerMode === 'p2p-media-loader' ? 'p2p-media-loader' : 'webtorrent'
+
+ if (mode === 'p2p-media-loader') {
+ const hlsPlaylist = this.video.getHlsPlaylist()
+
+ const p2pMediaLoader = {
+ playlistUrl: hlsPlaylist.playlistUrl,
+ segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
+ redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
+ trackerAnnounce: this.video.trackerUrls,
+ videoFiles: this.video.files
+ } as P2PMediaLoaderOptions
+
+ Object.assign(options, { p2pMediaLoader })
+ }
+
+ this.zone.runOutsideAngular(async () => {
+ this.player = await PeertubePlayerManager.initialize(mode, options)
+ this.theaterEnabled = this.player.theaterEnabled
+
+ this.player.on('customError', ({ err }: { err: any }) => this.handleError(err))
+
+ this.player.on('timeupdate', () => {
+ this.currentTime = Math.floor(this.player.currentTime())
+ })
+
+ this.player.one('ended', () => {
+ if (this.playlist) {
+ this.zone.run(() => this.navigateToNextPlaylistVideo())
+ }
+ })
+
+ this.player.one('stopped', () => {
+ if (this.playlist) {
+ this.zone.run(() => this.navigateToNextPlaylistVideo())
+ }
+ })
+
+ this.player.on('theaterChange', (_: any, enabled: boolean) => {
+ this.zone.run(() => this.theaterEnabled = enabled)