Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions assets/css/player.css
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,17 @@ button:focus-visible {
color: var(--accent-primary);
}

/* `hidden` has to win over the display: flex above. */
.jellyjump-btn[hidden] {
display: none;
}

/* Backward is set: the play arrow points back, so it is plain which way Play
will go. The pause bars are symmetrical, so they read the same either way. */
.jellyjump-btn.is-backward svg {
transform: scaleX(-1);
}

/* -----------------------------------------
Playlist Settings Menu
----------------------------------------- */
Expand Down
72 changes: 63 additions & 9 deletions assets/js/core/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ export class CorePlayer {
this.subtitles = new PlayerSubtitles(this);
// Playing backwards runs beside the forward pipeline, not through it.
this.reverse = new ReversePlayback(this);
// Which way Play goes. A setting, like speed: once backward, play,
// pause, seeks and speed changes all keep going backward until it is
// switched back, or another file is opened.
this.direction = 'forward';
this.loop = new PlayerLoopControl(this);
this.thumbnails = new PlayerThumbnails(this);
this.controlBar = new PlayerControlBar(this);
Expand Down Expand Up @@ -440,8 +444,14 @@ export class CorePlayer {
return resetPlayer(this);
}
async _cleanupForLoad() {
// Nothing to hand back to: the media is being replaced.
// Nothing to hand back to: the media is being replaced. A new file
// always starts forward, so it never surprises anyone by running
// backwards.
await this.reverse?.stop({ reposition: false });
if (this.direction !== 'forward') {
this.direction = 'forward';
this._updatePlayPauseUI();
}
// Always, not only when leaving YouTube: this runs before every load,
// and a playing iframe left visible would sit on top of the next video.
// Suspended rather than destroyed — load() destroys it once it knows
Expand All @@ -461,25 +471,53 @@ export class CorePlayer {
async _handleVisibilityChange() { return handlePlayerVisibilityChange(this); }
togglePlay() {
if (this.reverse?.active) { this.pause(); return; }
if (this.direction === 'backward' && this.engine !== 'youtube') { this.play(); return; }
togglePlayerPlay(this);
}
/** Play backwards from here, or stop doing so. */
async toggleReverse() {
if (this.reverse.active) return this.reverse.stop();
return this.reverse.start();

/**
* Switch which way Play goes. While playing, the switch takes effect at
* once, from where playback is; while paused, the next Play goes the new
* way.
* @returns {Promise<{reason?: string}>} a reason, in words for the user,
* when playing backwards is not possible for this media
*/
async toggleDirection() {
if (this.direction === 'forward') {
const reason = this.reverse.unavailableReason;
if (reason) return { reason };
const wasPlaying = this.isPlaying;
this.direction = 'backward';
this._updatePlayPauseUI();
if (wasPlaying) {
const result = await this._playBackward();
return result.started ? {} : { reason: result.reason };
}
return {};
}
const wasReversing = this.reverse.active;
this.direction = 'forward';
this._updatePlayPauseUI();
if (wasReversing) {
await this.reverse.stop();
await this.play();
}
return {};
}
_cycleSpeed(direction) { cyclePlayerSpeed(this, direction); }
_stepFrame(direction) { stepPlayerFrame(this, direction); }
async _seekTo(time) {
// A seek while playing backwards stops it; the seek decides the position.
if (this.reverse?.active) await this.reverse.stop({ reposition: false });
// Playing backwards carries on from wherever the seek lands.
const wasReversing = !!this.reverse?.active;
if (wasReversing) await this.reverse.stop({ reposition: false });
if (this.engine === 'youtube') {
this.youtube?.seek(time);
this.currentTime = Math.max(0, time);
this._updateProgress();
return;
}
return seekPlayerTo(this, time);
await seekPlayerTo(this, time);
if (wasReversing) await this._playBackward();
}
_requestSeek(time) { requestPlayerSeek(this, time); }
_completeMedia() { completePlayerMedia(this); }
Expand All @@ -499,11 +537,23 @@ export class CorePlayer {
// ─── Play ────────────────────────────────────────────────────────────────────
async play() {
if (this.engine === 'youtube') { this.youtube?.play(); return; }
if (this.direction === 'backward') return this._playBackward();
// Forwards from wherever playing backwards got to.
if (this.reverse?.active) await this.reverse.stop();
return playPlayer(this);
}

/**
* Play backwards, saying why if it cannot start.
* @private
*/
async _playBackward() {
if (this.reverse.active) return { started: true };
const result = await this.reverse.start();
if (!result.started && result.reason) this.trigger('reversefailed', { reason: result.reason });
return result;
}

// ─── Pause ───────────────────────────────────────────────────────────────────
pause(showOverlay = true) {
if (this.reverse?.active) {
Expand All @@ -527,7 +577,11 @@ export class CorePlayer {
this.youtube?.setRate(rate);
return;
}
return setPlayerPlaybackRate(this, rate);
// Playing backwards picks the new speed up from where it is.
const wasReversing = !!this.reverse?.active;
if (wasReversing) await this.reverse.stop({ reposition: false });
await setPlayerPlaybackRate(this, rate);
if (wasReversing) await this._playBackward();
}

// ─── Volume / Mute ───────────────────────────────────────────────────────────
Expand Down
5 changes: 5 additions & 0 deletions assets/js/core/playback/MediaLifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ export async function loadPlayerMedia(player, url, autoplay = false, videoId = n
player.currentVideoId = videoId || url;
player._setLoading(true);
await loadPlayerYouTube(player, youtube, autoplay);
// The direction button hides for YouTube.
player._updatePlayPauseUI();
Logger.log('Media loaded successfully (youtube)');
return;
}
Expand All @@ -655,6 +657,9 @@ export async function loadPlayerMedia(player, url, autoplay = false, videoId = n
player._updateSubtitleMenu();

if (!player.isLive) player._setLoading(false);
// Now that it is known whether this is live and has a picture, the
// direction button shows or hides to match.
player._updatePlayPauseUI();
Logger.log('Media loaded successfully');

} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions assets/js/core/playback/PlaybackState.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ export function playerSeek(player, e) {

export function playerScrubStart(player, e) {
player.isScrubbing = true;
player.scrubWasPlaying = player.isPlaying;
// Playing backwards counts as playing: it resumes, backwards, on release.
player.scrubWasPlaying = player.isPlaying || !!player.reverse?.active;

if (player.isPlaying) player.pause(false);
if (player.scrubWasPlaying) player.pause(false);

// Wake the context pause() just suspended while we are guaranteed to be
// inside the input event (scrub start is always user input), so the
Expand Down
Loading
Loading