Skip to content

Commit

Permalink
Added a "previous" button on player when watching playlist
Browse files Browse the repository at this point in the history
Implements Chocobozzz#3485
  • Loading branch information
Poslovitch committed Apr 18, 2021
1 parent 4646054 commit 5924953
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ export class VideoWatchPlaylistComponent {
this.onPlaylistVideosNearOfBottom(position)
}

findPreviousPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
if (this.currentPlaylistPosition <= 1) {
// we have reached the top of the playlist: either loop or stop
if (this.loopPlaylist) {
this.currentPlaylistPosition = position = this.playlistPagination.totalItems
} else {
return
}
}
const previous = this.playlistElements.find(e => e.position === position)

if (!previous || !previous.video) {
return this.findPreviousPlaylistVideo(position - 1)
}

return previous
}

navigateToPreviousPlaylistVideo () {
const previous = this.findPreviousPlaylistVideo(this.currentPlaylistPosition - 1)
if (!previous) return

const start = previous.startTimestamp
const stop = previous.stopTimestamp
this.router.navigate([],{ queryParams: { playlistPosition: previous.position, start, stop } })
}

findNextPlaylistVideo (position = this.currentPlaylistPosition): VideoPlaylistElement {
if (this.currentPlaylistPosition >= this.playlistPagination.totalItems) {
// we have reached the end of the playlist: either loop or stop
Expand Down
4 changes: 4 additions & 0 deletions client/src/app/+videos/+video-watch/video-watch.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
common: {
autoplay: this.isAutoplay(),
nextVideo: () => this.zone.run(() => this.autoplayNext()),
previousVideo: () => this.zone.run(() => {
// FIXME: Only show if this is a playlist
if (this.playlist) this.zone.run(() => this.videoWatchPlaylist.navigateToPreviousPlaylistVideo())
}),

playerElement: this.playerElement,
onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
Expand Down

0 comments on commit 5924953

Please sign in to comment.