Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TV Support for 'Ask to Skip' #6295

Open
wants to merge 11 commits into
base: release-10.10.z
Choose a base branch
from
5 changes: 1 addition & 4 deletions src/components/playback/playbackmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { MediaError } from 'types/mediaError';
import { getMediaError } from 'utils/mediaError';
import { toApi } from 'utils/jellyfin-apiclient/compat';
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind.js';
import browser from 'scripts/browser.js';
import { bindSkipSegment } from './skipsegment.ts';

const UNLIMITED_ITEMS = -1;
Expand Down Expand Up @@ -3687,9 +3686,7 @@ export class PlaybackManager {
}

bindMediaSegmentManager(self);
if (!browser.tv && !browser.xboxOne && !browser.ps4) {
this._skipSegment = bindSkipSegment(self);
}
this._skipSegment = bindSkipSegment(self);
}

getCurrentPlayer() {
Expand Down
70 changes: 42 additions & 28 deletions src/components/playback/skipsegment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,54 @@ import './skipbutton.scss';
import dom from 'scripts/dom';
import globalize from 'lib/globalize';
import * as userSettings from 'scripts/settings/userSettings';
import focusManager from 'components/focusManager';
import layoutManager from 'components/layoutManager';

interface ShowOptions {
animate?: boolean;
keep?: boolean;
focus?: boolean;
}

function onHideComplete(this: HTMLButtonElement) {
if (this) {
this.classList.add('hide');
}
}

class SkipSegment extends PlaybackSubscriber {
private skipElement: HTMLButtonElement | undefined;
private skipElement: HTMLButtonElement | null;
private currentSegment: MediaSegmentDto | null | undefined;
private hideTimeout: ReturnType<typeof setTimeout> | null | undefined;

constructor(playbackManager: PlaybackManager) {
super(playbackManager);

this.skipElement = null;
this.onOsdChanged = this.onOsdChanged.bind(this);
}

onHideComplete() {
if (this.skipElement) {
this.skipElement.classList.add('hide');
}
}

createSkipElement() {
if (!this.skipElement && this.currentSegment) {
const elem = document.createElement('button');
elem.classList.add('skip-button');
elem.classList.add('hide');
elem.classList.add('skip-button-hidden');

elem.addEventListener('click', () => {
const time = this.playbackManager.currentTime() * TICKS_PER_MILLISECOND;
if (this.currentSegment?.EndTicks) {
if (time < this.currentSegment.EndTicks - TICKS_PER_SECOND) {
this.playbackManager.seek(this.currentSegment.EndTicks);
} else {
this.hideSkipButton();
let buttonHtml = '';

buttonHtml += '<button is="emby-button" class="skip-button hide skip-button-hidden"></button>';
viown marked this conversation as resolved.
Show resolved Hide resolved

document.body.insertAdjacentHTML('beforeend', buttonHtml);

this.skipElement = document.body.querySelector('.skip-button');
if (this.skipElement) {
this.skipElement.addEventListener('click', () => {
const time = this.playbackManager.currentTime() * TICKS_PER_MILLISECOND;
if (this.currentSegment?.EndTicks) {
if (time < this.currentSegment.EndTicks - TICKS_PER_SECOND) {
this.playbackManager.seek(this.currentSegment.EndTicks);
} else {
this.hideSkipButton();
}
}
}
});

document.body.appendChild(elem);
this.skipElement = elem;
});
}
}
}

Expand All @@ -66,7 +71,7 @@ class SkipSegment extends PlaybackSubscriber {
const elem = this.skipElement;
if (elem) {
this.clearHideTimeout();
dom.removeEventListener(elem, dom.whichTransitionEvent(), this.onHideComplete, {
dom.removeEventListener(elem, dom.whichTransitionEvent(), onHideComplete, {
once: true
});
elem.classList.remove('hide');
Expand All @@ -78,6 +83,11 @@ class SkipSegment extends PlaybackSubscriber {

void elem.offsetWidth;

const hasFocus = document.activeElement && focusManager.isCurrentlyFocusable(document.activeElement);
if (options.focus && !hasFocus) {
focusManager.focus(elem);
}

requestAnimationFrame(() => {
elem.classList.remove('skip-button-hidden');

Expand All @@ -97,7 +107,7 @@ class SkipSegment extends PlaybackSubscriber {
requestAnimationFrame(() => {
elem.classList.add('skip-button-hidden');

dom.addEventListener(elem, dom.whichTransitionEvent(), this.onHideComplete, {
dom.addEventListener(elem, dom.whichTransitionEvent(), onHideComplete, {
once: true
});
});
Expand All @@ -116,7 +126,8 @@ class SkipSegment extends PlaybackSubscriber {
if (isOpen) {
this.showSkipButton({
animate: false,
keep: true
keep: true,
focus: false
});
} else if (!this.hideTimeout) {
this.hideSkipButton();
Expand All @@ -140,7 +151,10 @@ class SkipSegment extends PlaybackSubscriber {

this.setButtonText();

this.showSkipButton({ animate: true });
this.showSkipButton({
animate: true,
focus: layoutManager.tv
});
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/controllers/playback/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,10 @@ export default function (view) {
}
return;
case 'Enter':
playbackManager.playPause(currentPlayer);
showOsd(btnPlayPause);
if (e.target.tagName !== 'BUTTON') {
playbackManager.playPause(currentPlayer);
showOsd(btnPlayPause);
}
return;
}
}
Expand Down
Loading