+ await this.ensurePluginsAreLoaded(config, serverTranslations)
+
+ const videoInfo: VideoDetails = videoInfoTmp
+
+ const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager
+ const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse)
+
+ this.loadParams(videoInfo)
+
+ const playlistPlugin = this.currentPlaylistElement
+ ? {
+ elements: this.playlistElements,
+ playlist: this.playlist,
+
+ getCurrentPosition: () => this.currentPlaylistElement.position,
+
+ onItemClicked: (videoPlaylistElement: VideoPlaylistElement) => {
+ this.currentPlaylistElement = videoPlaylistElement
+
+ this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
+ .catch(err => console.error(err))
+ }
+ }
+ : undefined
+
+ const options: PeertubePlayerManagerOptions = {
+ common: {
+ // Autoplay in playlist mode
+ autoplay: alreadyHadPlayer ? true : this.autoplay,
+ controls: this.controls,
+ muted: this.muted,
+ loop: this.loop,
+
+ captions: videoCaptions.length !== 0,
+ subtitle: this.subtitle,
+
+ startTime: this.playlist ? this.currentPlaylistElement.startTimestamp : this.startTime,
+ stopTime: this.playlist ? this.currentPlaylistElement.stopTimestamp : this.stopTime,
+
+ nextVideo: this.playlist ? () => this.playNextVideo() : undefined,
+ hasNextVideo: this.playlist ? () => !!this.getNextPlaylistElement() : undefined,
+
+ previousVideo: this.playlist ? () => this.playPreviousVideo() : undefined,
+ hasPreviousVideo: this.playlist ? () => !!this.getPreviousPlaylistElement() : undefined,
+
+ playlist: playlistPlugin,
+
+ videoCaptions,
+ inactivityTimeout: 2500,
+ videoViewUrl: this.getVideoUrl(videoInfo.uuid) + '/views',
+ videoUUID: videoInfo.uuid,
+
+ isLive: videoInfo.isLive,
+
+ playerElement: this.playerElement,
+ onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
+
+ videoDuration: videoInfo.duration,
+ enableHotkeys: true,
+ peertubeLink: this.peertubeLink,
+ poster: window.location.origin + videoInfo.previewPath,
+ theaterButton: false,
+
+ serverUrl: window.location.origin,
+ language: navigator.language,
+ embedUrl: window.location.origin + videoInfo.embedPath,
+ embedTitle: videoInfo.name
+ },
+
+ webtorrent: {
+ videoFiles: videoInfo.files
+ }
+ }
+
+ if (this.mode === 'p2p-media-loader') {
+ const hlsPlaylist = videoInfo.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
+
+ Object.assign(options, {
+ p2pMediaLoader: {
+ playlistUrl: hlsPlaylist.playlistUrl,
+ segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
+ redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
+ trackerAnnounce: videoInfo.trackerUrls,
+ videoFiles: hlsPlaylist.files
+ } as P2PMediaLoaderOptions
+ })
+ }
+
+ this.player = await PeertubePlayerManager.initialize(this.mode, options, (player: videojs.Player) => this.player = player)
+ this.player.on('customError', (event: any, data: any) => this.handleError(data.err, serverTranslations))
+
+ window[ 'videojsPlayer' ] = this.player
+
+ this.buildCSS()
+
+ await this.buildDock(videoInfo, config)
+
+ this.initializeApi()
+
+ this.removePlaceholder()
+
+ if (this.isPlaylistEmbed()) {
+ await this.buildPlaylistManager()
+
+ this.player.playlist().updateSelected()
+
+ this.player.on('stopped', () => {
+ this.playNextVideo()
+ })
+ }
+
+ this.runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video: videoInfo })
+ }
+
+ private async initCore () {
+ if (this.userTokens) this.setHeadersFromTokens()
+
+ this.configPromise = this.loadConfig()
+ this.translationsPromise = TranslationsManager.getServerTranslations(window.location.origin, navigator.language)
+ this.PeertubePlayerManagerModulePromise = import('../../assets/player/peertube-player-manager')
+
+ let videoId: string
+
+ if (this.isPlaylistEmbed()) {
+ const playlistId = this.getResourceId()
+ const res = await this.loadPlaylist(playlistId)
+ if (!res) return undefined
+
+ this.playlist = await res.playlistResponse.json()
+
+ const playlistElementResult = await res.videosResponse.json()
+ this.playlistElements = await this.loadAllPlaylistVideos(playlistId, playlistElementResult)
+
+ const params = new URL(window.location.toString()).searchParams
+ const playlistPositionParam = this.getParamString(params, 'playlistPosition')
+
+ let position = 1
+
+ if (playlistPositionParam) {
+ position = parseInt(playlistPositionParam + '', 10)
+ }
+
+ this.currentPlaylistElement = this.playlistElements.find(e => e.position === position)
+ if (!this.currentPlaylistElement || !this.currentPlaylistElement.video) {
+ console.error('Current playlist element is not valid.', this.currentPlaylistElement)
+ this.currentPlaylistElement = this.getNextPlaylistElement()
+ }
+
+ if (!this.currentPlaylistElement) {
+ console.error('This playlist does not have any valid element.')
+ const serverTranslations = await this.translationsPromise
+ this.playlistFetchError(serverTranslations)
+ return
+ }