X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-watch%2Fvideo-watch-playlist.component.ts;h=c5ed36000130b2964387601d942b5f606b1eb1b6;hb=31174a272a65c83c8d3e10e9d5d59786bd05682a;hp=c6b04fd4bf5039390ed674dbfea01c0e3fa7097b;hpb=88a7f93f8e5666f44121a2e3cf9d33d74c472aa7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/videos/+video-watch/video-watch-playlist.component.ts index c6b04fd4b..c5ed36000 100644 --- a/client/src/app/videos/+video-watch/video-watch-playlist.component.ts +++ b/client/src/app/videos/+video-watch/video-watch-playlist.component.ts @@ -44,11 +44,13 @@ export class VideoWatchPlaylistComponent { private videoPlaylist: VideoPlaylistService, private router: Router ) { + // defaults to true this.autoPlayNextVideoPlaylist = this.auth.isLoggedIn() ? this.auth.getUser().autoPlayNextVideoPlaylist : peertubeLocalStorage.getItem(VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) !== 'false' this.setAutoPlayNextVideoPlaylistSwitchText() + // defaults to false this.loopPlaylist = peertubeSessionStorage.getItem(VideoWatchPlaylistComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) === 'true' this.setLoopPlaylistSwitchText() } @@ -127,23 +129,31 @@ export class VideoWatchPlaylistComponent { this.onPlaylistVideosNearOfBottom() } - navigateToNextPlaylistVideo (_next: VideoPlaylistElement = null) { - if (this.currentPlaylistPosition < this.playlistPagination.totalItems) { - const next = _next || this.playlistElements.find(e => e.position === this.currentPlaylistPosition + 1) - - if (!next || !next.video) { - this.currentPlaylistPosition++ - this.navigateToNextPlaylistVideo() + findNextPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement { + if (this.currentPlaylistPosition >= this.playlistPagination.totalItems) { + // we have reached the end of the playlist: either loop or stop + if (this.loopPlaylist) { + this.currentPlaylistPosition = position = 0 + } else { return } + } + + const next = this.playlistElements.find(e => e.position === position) - const start = next.startTimestamp - const stop = next.stopTimestamp - this.router.navigate([],{ queryParams: { videoId: next.video.uuid, start, stop } }) - } else if (this.loopPlaylist) { - this.currentPlaylistPosition = 0 - this.navigateToNextPlaylistVideo(this.playlistElements.find(e => e.position === this.currentPlaylistPosition)) + if (!next || !next.video) { + return this.findNextPlaylistVideo(position + 1) } + + return next + } + + navigateToNextPlaylistVideo () { + const next = this.findNextPlaylistVideo(this.currentPlaylistPosition + 1) + if (!next) return + const start = next.startTimestamp + const stop = next.stopTimestamp + this.router.navigate([],{ queryParams: { videoId: next.video.uuid, start, stop } }) } switchAutoPlayNextVideoPlaylist () {