+ private loadRouteParams () {
+ this.paramsSub = this.route.params.subscribe(routeParams => {
+ const videoId = routeParams['videoId']
+ if (videoId) return this.loadVideo({ videoId, forceAutoplay: false })
+
+ const playlistId = routeParams['playlistId']
+ if (playlistId) return this.loadPlaylist(playlistId)
+ })
+ }
+
+ private loadRouteQuery () {
+ this.queryParamsSub = this.route.queryParams.subscribe(queryParams => {
+ // Handle the ?playlistPosition
+ const positionParam = queryParams['playlistPosition'] ?? 1
+
+ this.playlistPosition = positionParam === 'last'
+ ? -1 // Handle the "last" index
+ : parseInt(positionParam + '', 10)
+
+ if (isNaN(this.playlistPosition)) {
+ logger.error(`playlistPosition query param '${positionParam}' was parsed as NaN, defaulting to 1.`)
+ this.playlistPosition = 1
+ }
+
+ this.videoWatchPlaylist.updatePlaylistIndex(this.playlistPosition)
+
+ const start = queryParams['start']
+ if (this.player && start) this.player.currentTime(parseInt(start, 10))
+ })
+ }
+
+ private loadVideo (options: {
+ videoId: string
+ forceAutoplay: boolean
+ }) {
+ const { videoId, forceAutoplay } = options
+
+ if (this.isSameElement(this.video, videoId)) return