+ await this.loadPlugins(serverTranslations)
+
+ const videoInfo: VideoDetails = videoInfoTmp
+
+ const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager
+ const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse)
+
+ 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,
+
+ p2pEnabled: this.p2pEnabled,
+
+ 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',
+ videoShortUUID: videoInfo.shortUUID,
+ 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,
+
+ errorNotifier: () => {
+ // Empty, we don't have a notifier in the embed
+ }
+ },
+
+ webtorrent: {
+ videoFiles: videoInfo.files
+ },
+
+ pluginsManager: this.pluginsManager
+ }
+
+ 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()
+
+ this.buildDock(videoInfo)
+
+ this.initializeApi()
+
+ this.removePlaceholder()
+
+ if (this.isPlaylistEmbed()) {
+ await this.buildPlaylistManager()
+
+ this.player.playlist().updateSelected()
+
+ this.player.on('stopped', () => {
+ this.playNextVideo()
+ })
+ }
+
+ this.pluginsManager.runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video: videoInfo })
+ }
+
+ private async initCore () {
+ if (this.userTokens) this.setHeadersFromTokens()
+
+ 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