aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/+videos/+video-watch/video-watch-playlist.component.ts53
1 files changed, 20 insertions, 33 deletions
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 cc908b924..a70167da5 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
@@ -137,26 +137,8 @@ export class VideoWatchPlaylistComponent {
137 this.onPlaylistVideosNearOfBottom(position) 137 this.onPlaylistVideosNearOfBottom(position)
138 } 138 }
139 139
140 findPreviousPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
141 if (this.currentPlaylistPosition <= 1) {
142 // we have reached the top of the playlist: either loop or stop
143 if (this.loopPlaylist) {
144 this.currentPlaylistPosition = position = this.playlistPagination.totalItems
145 } else {
146 return
147 }
148 }
149 const previous = this.playlistElements.find(e => e.position === position)
150
151 if (!previous || !previous.video) {
152 return this.findPreviousPlaylistVideo(position - 1)
153 }
154
155 return previous
156 }
157
158 navigateToPreviousPlaylistVideo () { 140 navigateToPreviousPlaylistVideo () {
159 const previous = this.findPreviousPlaylistVideo(this.currentPlaylistPosition - 1) 141 const previous = this.findPlaylistVideo(this.currentPlaylistPosition - 1, 'previous')
160 if (!previous) return 142 if (!previous) return
161 143
162 const start = previous.startTimestamp 144 const start = previous.startTimestamp
@@ -164,27 +146,32 @@ export class VideoWatchPlaylistComponent {
164 this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } }) 146 this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } })
165 } 147 }
166 148
167 findNextPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement { 149 findPlaylistVideo (position: number, type: 'previous' | 'next'): VideoPlaylistElement {
168 if (this.currentPlaylistPosition >= this.playlistPagination.totalItems) { 150 if (
169 // we have reached the end of the playlist: either loop or stop 151 (type === 'next' && position > this.playlistPagination.totalItems) ||
170 if (this.loopPlaylist) { 152 (type === 'previous' && position < 1)
171 this.currentPlaylistPosition = position = 0 153 ) {
172 } else { 154 // End of the playlist: end the recursion if we're not in the loop mode
173 return 155 if (!this.loopPlaylist) return
174 } 156
157 // Loop mode
158 position = type === 'previous'
159 ? this.playlistPagination.totalItems
160 : 1
175 } 161 }
176 162
177 const next = this.playlistElements.find(e => e.position === position) 163 const found = this.playlistElements.find(e => e.position === position)
164 if (found && found.video) return found
178 165
179 if (!next || !next.video) { 166 const newPosition = type === 'previous'
180 return this.findNextPlaylistVideo(position + 1) 167 ? position - 1
181 } 168 : position + 1
182 169
183 return next 170 return this.findPlaylistVideo(newPosition, type)
184 } 171 }
185 172
186 navigateToNextPlaylistVideo () { 173 navigateToNextPlaylistVideo () {
187 const next = this.findNextPlaylistVideo(this.currentPlaylistPosition + 1) 174 const next = this.findPlaylistVideo(this.currentPlaylistPosition + 1, 'next')
188 if (!next) return 175 if (!next) return
189 176
190 const start = next.startTimestamp 177 const start = next.startTimestamp