+
+ 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
+
+ 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
+ }
+
+ videoId = this.currentPlaylistElement.video.uuid
+ } else {
+ videoId = this.getResourceId()
+ }
+
+ return this.loadVideoAndBuildPlayer(videoId)