mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-26 08:29:41 -05:00
unify and clean more things
This commit is contained in:
8 files changed
+204
-289
No files matched your search
@@ -136,7 +136,6 @@ import {
|
||||
import { useAudioVisualizer } from "@/composables/player/useAudioVisualizer.ts";
|
||||
import { useEmbeddedArtwork } from "@/composables/player/useEmbeddedArtwork.ts";
|
||||
import { useDoubleTapSeek } from "@/composables/player/useDoubleTapSeek.ts";
|
||||
import { useFullscreenState } from "@/composables/player/useFullscreenState.ts";
|
||||
import { useGestureState } from "@/composables/player/useGestureState.ts";
|
||||
import { useMediaKeyboard } from "@/composables/player/useMediaKeyboard.ts";
|
||||
import { type MountedFileKey, resolveMountedFileKey, useMediaPlayer } from "@/composables/player/useMediaPlayer.ts";
|
||||
@@ -144,7 +143,7 @@ import { useMediaSession } from "@/composables/player/useMediaSession.ts";
|
||||
import { usePlaybackQueue } from "@/composables/player/usePlaybackQueue.ts";
|
||||
import { useSwipeNavigationGestures } from "@/composables/player/useSwipeNavigationGestures.ts";
|
||||
import { useI18n } from "@/i18n/index.ts";
|
||||
import { enableSeekOnRelease, blockSeekOnInput } from "@/player/seekOnRelease.js";
|
||||
import { enableSeekOnRelease } from "@/player/seekOnRelease.js";
|
||||
import { router } from "@/router/index.ts";
|
||||
import { getters, mutations, state } from "@/store/index.ts";
|
||||
import type { FileListItem } from "@/store/types.ts";
|
||||
@@ -311,19 +310,17 @@ const swipe = useSwipeNavigationGestures({
|
||||
onClosePreview: () => emit("close-preview"),
|
||||
});
|
||||
const { speedToastVisible, speedToastMessage, setupSwipeGestures, teardownSwipeGestures, clearDismissAnimTimers } = swipe;
|
||||
const { onFullscreenEnter, onFullscreenExit } = useFullscreenState({ onEnter: swipe.resetEdgeGestureImmediate });
|
||||
const {
|
||||
createPlayer,
|
||||
onPlayerEvent,
|
||||
getActiveMediaElement,
|
||||
stopMediaElement,
|
||||
rememberFullscreenForTransition,
|
||||
resumeFullscreenAfterNavigation,
|
||||
destroyPlayer,
|
||||
stopIfRouteLeftThisFile,
|
||||
togglePlayPause,
|
||||
handleMediaEnd,
|
||||
} = useMediaPlayer({
|
||||
kind: "audio",
|
||||
player,
|
||||
getMediaElement: () => audioElement.value,
|
||||
getRequestedFile: () => props.req,
|
||||
@@ -416,70 +413,6 @@ async function stripPlaybackTimeFromUrl(): Promise<void> {
|
||||
await router.replace({ path: route.path, query: nextQuery, hash: route.hash });
|
||||
}
|
||||
|
||||
const playerOptions = computed<Plyr.Options>(() => {
|
||||
const controlsDesktop = [
|
||||
"play-large",
|
||||
"rewind",
|
||||
"play",
|
||||
"fast-forward",
|
||||
"progress",
|
||||
"current-time",
|
||||
"duration",
|
||||
"mute",
|
||||
"volume",
|
||||
"captions",
|
||||
"settings",
|
||||
"fullscreen",
|
||||
];
|
||||
const controlsMobile = [
|
||||
"play-large",
|
||||
"play",
|
||||
"progress",
|
||||
"current-time",
|
||||
"duration",
|
||||
"mute",
|
||||
"volume",
|
||||
"captions",
|
||||
"settings",
|
||||
"fullscreen",
|
||||
];
|
||||
return {
|
||||
controls: isMobile.value ? controlsMobile : controlsDesktop,
|
||||
settings: ["captions", "quality", "speed", "playback", "loop"],
|
||||
i18n: {
|
||||
playback: t("player.playbackMode"),
|
||||
loop: t("player.loop"),
|
||||
},
|
||||
speed: {
|
||||
selected: 1,
|
||||
options: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2],
|
||||
},
|
||||
disableContextMenu: true,
|
||||
seekTime: 10,
|
||||
hideControls: true,
|
||||
keyboard: { focused: true, global: true },
|
||||
tooltips: { controls: true, seek: true },
|
||||
loop: { active: false },
|
||||
blankVideo: "",
|
||||
muted: false,
|
||||
autoplay: false,
|
||||
playsinline: true,
|
||||
clickToPlay: false, // we manage this ourselves with the gestures, plyr has a issue where this doesn't work in mobile.
|
||||
resetOnEnd: false,
|
||||
preload: "none",
|
||||
fullscreen: {
|
||||
enabled: true,
|
||||
fallback: true,
|
||||
iosNative: true,
|
||||
container: ".media-player",
|
||||
},
|
||||
iconUrl: `${globalVars.baseURL}public/static/img/plyr.svg`,
|
||||
listeners: {
|
||||
seek: blockSeekOnInput,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
function setupPlayerEvents(): void {
|
||||
const current = player.value;
|
||||
if (!current) return;
|
||||
@@ -505,8 +438,6 @@ function setupPlayerEvents(): void {
|
||||
["loadedmetadata", updateMediaSessionPlaybackState],
|
||||
["ratechange", updateMediaSessionPlaybackState],
|
||||
["canplay", updateMediaSessionPlaybackState],
|
||||
["enterfullscreen", onFullscreenEnter],
|
||||
["exitfullscreen", onFullscreenExit],
|
||||
];
|
||||
for (const [event, handler] of events) {
|
||||
onPlayerEvent(event, handler);
|
||||
@@ -524,7 +455,7 @@ async function mountPlayer(): Promise<void> {
|
||||
mountedFile = resolveMountedFileKey(props.req?.source, props.req?.path);
|
||||
await stripPlaybackTimeFromUrl();
|
||||
if (!audioElement.value || tornDown || player.value) return;
|
||||
createPlayer(playerOptions.value);
|
||||
createPlayer();
|
||||
if (!player.value) return;
|
||||
setupMediaSession({
|
||||
title: metadata.value?.title || fileName.value,
|
||||
@@ -534,7 +465,6 @@ async function mountPlayer(): Promise<void> {
|
||||
});
|
||||
setupPlayerEvents();
|
||||
seekOnReleaseCleanup = enableSeekOnRelease(player.value);
|
||||
resumeFullscreenAfterNavigation();
|
||||
} finally {
|
||||
mountInProgress = false;
|
||||
}
|
||||
@@ -564,15 +494,11 @@ function destroy(): void {
|
||||
}
|
||||
mountedFile = null;
|
||||
const media = getActiveMediaElement();
|
||||
const isTransition = state.navigation.isTransitioning;
|
||||
|
||||
if (media) {
|
||||
stopMediaElement(media);
|
||||
}
|
||||
if (player.value) {
|
||||
if (isTransition) {
|
||||
rememberFullscreenForTransition();
|
||||
}
|
||||
teardownSwipeGestures();
|
||||
teardownDoubleTapSeek();
|
||||
clearRewindForwardFeedback();
|
||||
@@ -614,48 +540,7 @@ onBeforeUnmount(() => {
|
||||
defineExpose({ destroy });
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* Hide the overlaid play button in audio mode */
|
||||
.plyr--audio .plyr__control--overlaid {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide the captions button in audio mode */
|
||||
.plyr--audio .plyr__control[data-plyr="captions"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.plyr.plyr--audio {
|
||||
border-radius: var(--borderRadius);
|
||||
backdrop-filter: var(--panel-blur);
|
||||
background-color: var(--alt-background);
|
||||
}
|
||||
|
||||
.audio-controls-container .plyr .plyr__controls {
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
|
||||
.plyr--audio .plyr__control[data-plyr="fullscreen"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@media (width <= 768px) {
|
||||
.plyr--audio .plyr__control {
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
}
|
||||
.plyr--audio .plyr__progress__container {
|
||||
margin: 10px 0;
|
||||
}
|
||||
.plyr--audio .plyr__controls__items {
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.plyr--audio .plyr__control--play {
|
||||
transform: scale(1.25);
|
||||
}
|
||||
}
|
||||
|
||||
<style scoped>
|
||||
.audio-player-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -850,14 +735,6 @@ defineExpose({ destroy });
|
||||
padding: 0;
|
||||
padding-top: 1em;
|
||||
}
|
||||
.plyr.plyr--audio {
|
||||
padding: 1em;
|
||||
border-radius: 0;
|
||||
}
|
||||
.plyr--audio .plyr__controls {
|
||||
padding: 0;
|
||||
gap: 5px;
|
||||
}
|
||||
.album-art-container {
|
||||
margin-top: 1em;
|
||||
max-width: min(71vw);
|
||||
@@ -868,11 +745,6 @@ defineExpose({ destroy });
|
||||
}
|
||||
|
||||
@media (width <= 550px) {
|
||||
/* Time playing */
|
||||
.plyr--audio .plyr__time {
|
||||
font-size: 14px;
|
||||
margin: 0 5px;
|
||||
}
|
||||
.audio-left-column {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
@@ -889,3 +761,52 @@ defineExpose({ destroy });
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
.plyr.plyr--audio {
|
||||
border-radius: var(--borderRadius);
|
||||
backdrop-filter: var(--panel-blur);
|
||||
background-color: var(--alt-background);
|
||||
}
|
||||
|
||||
.audio-controls-container .plyr .plyr__controls {
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
|
||||
@media (width <= 768px) {
|
||||
.plyr--audio .plyr__control {
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
}
|
||||
.plyr--audio .plyr__progress__container {
|
||||
margin: 10px 0;
|
||||
}
|
||||
.plyr--audio .plyr__controls__items {
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.plyr--audio .plyr__control--play {
|
||||
transform: scale(1.25);
|
||||
}
|
||||
}
|
||||
|
||||
/* For small tablets and phones with big screen */
|
||||
@media (width <= 740px) {
|
||||
.plyr.plyr--audio {
|
||||
padding: 1em;
|
||||
border-radius: 0;
|
||||
}
|
||||
.plyr--audio .plyr__controls {
|
||||
padding: 0;
|
||||
gap: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 550px) {
|
||||
/* Time playing */
|
||||
.plyr--audio .plyr__time {
|
||||
font-size: 14px;
|
||||
margin: 0 5px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -137,7 +137,7 @@ import { useTranscodePlayback } from "@/composables/player/useTranscodePlayback.
|
||||
import { useI18n } from "@/i18n/index.ts";
|
||||
import { primePlay } from "@/player/playbackIntent.js";
|
||||
import { enableScrubPreview } from "@/player/scrubPreview.js";
|
||||
import { blockSeekOnInput, enableSeekOnRelease } from "@/player/seekOnRelease.js";
|
||||
import { enableSeekOnRelease } from "@/player/seekOnRelease.js";
|
||||
import { transcodeLog, transcodeWarn } from "@/player/transcodeDebug.js";
|
||||
import {
|
||||
normalizeTranscodeMode,
|
||||
@@ -239,7 +239,6 @@ let transcodeModeButtons: NodeListOf<HTMLButtonElement> | null = null;
|
||||
let transcodeModeValueSpan: HTMLElement | null = null;
|
||||
|
||||
// --- Derived state ---
|
||||
const isMobile = computed(() => getters.isMobile());
|
||||
const hasSubtitles = computed(() => props.subtitlesList.length > 0);
|
||||
const fileName = computed(() => (props.req.name ? props.req.name.replace(/\.[^/.]+$/, "") : ""));
|
||||
const { metadata, albumArtUrl, loadMediaMetadata, cleanupAlbumArt } = useEmbeddedArtwork({
|
||||
@@ -444,6 +443,7 @@ const {
|
||||
togglePlayPause,
|
||||
handleMediaEnd,
|
||||
} = useMediaPlayer({
|
||||
kind: "video",
|
||||
player,
|
||||
getMediaElement: () => videoElement.value,
|
||||
getRequestedFile: () => props.req,
|
||||
@@ -472,76 +472,20 @@ const settingsMenu = computed(() => {
|
||||
return base;
|
||||
});
|
||||
|
||||
const playerOptions = computed<Plyr.Options>(() => {
|
||||
const controlsDesktop = [
|
||||
"play-large",
|
||||
"rewind",
|
||||
"play",
|
||||
"fast-forward",
|
||||
"progress",
|
||||
"current-time",
|
||||
"duration",
|
||||
"mute",
|
||||
"volume",
|
||||
"captions",
|
||||
"settings",
|
||||
"fullscreen",
|
||||
];
|
||||
const controlsMobile = [
|
||||
"play-large",
|
||||
"play",
|
||||
"progress",
|
||||
"current-time",
|
||||
"duration",
|
||||
"mute",
|
||||
"volume",
|
||||
"captions",
|
||||
"settings",
|
||||
"fullscreen",
|
||||
];
|
||||
return {
|
||||
controls: isMobile.value ? controlsMobile : controlsDesktop,
|
||||
settings: settingsMenu.value,
|
||||
i18n: {
|
||||
playback: t("player.playbackMode"),
|
||||
captionSize: t("player.captionSize"),
|
||||
loop: t("player.loop"),
|
||||
transcodeMode: t("general.transcode"),
|
||||
},
|
||||
speed: {
|
||||
selected: 1,
|
||||
options: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2],
|
||||
},
|
||||
disableContextMenu: true,
|
||||
seekTime: 10,
|
||||
hideControls: true,
|
||||
keyboard: { focused: true, global: true },
|
||||
tooltips: { controls: true, seek: !scrubPreviewEnabled.value },
|
||||
loop: { active: false },
|
||||
blankVideo: "",
|
||||
muted: false,
|
||||
autoplay: false,
|
||||
playsinline: true,
|
||||
clickToPlay: false, // we manage this ourselves with the gestures, plyr has a issue where this doesn't work in mobile.
|
||||
resetOnEnd: false,
|
||||
preload: "none",
|
||||
fullscreen: {
|
||||
enabled: true,
|
||||
fallback: true,
|
||||
iosNative: true,
|
||||
container: ".media-player",
|
||||
},
|
||||
iconUrl: `${globalVars.baseURL}public/static/img/plyr.svg`,
|
||||
captions: {
|
||||
active: false,
|
||||
language: "auto",
|
||||
update: true,
|
||||
},
|
||||
listeners: {
|
||||
seek: blockSeekOnInput,
|
||||
},
|
||||
};
|
||||
});
|
||||
/** The Plyr options only the video player needs */
|
||||
const videoPlyrOptions = computed<Plyr.Options>(() => ({
|
||||
settings: settingsMenu.value,
|
||||
i18n: {
|
||||
captionSize: t("player.captionSize"),
|
||||
transcodeMode: t("general.transcode"),
|
||||
},
|
||||
tooltips: { controls: true, seek: !scrubPreviewEnabled.value },
|
||||
captions: {
|
||||
active: false,
|
||||
language: "auto",
|
||||
update: true,
|
||||
},
|
||||
}));
|
||||
|
||||
/** Plyr captions menu: show format only (e.g. `.srt`, `.ass`), not the video basename. */
|
||||
function subtitleTrackLabel(sub: SubtitleTrack): string {
|
||||
@@ -835,7 +779,7 @@ async function mountPlayer(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
createPlayer(playerOptions.value);
|
||||
createPlayer(videoPlyrOptions.value);
|
||||
if (!player.value) {
|
||||
return;
|
||||
}
|
||||
@@ -1227,13 +1171,59 @@ onBeforeUnmount(() => {
|
||||
defineExpose({ destroy });
|
||||
</script>
|
||||
|
||||
<style >
|
||||
|
||||
<style scoped>
|
||||
.media-video-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.video-player-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #000;
|
||||
}
|
||||
|
||||
.video-loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
background: rgb(0 0 0 / 35%);
|
||||
}
|
||||
|
||||
/* Transcode offer (shown instead of the player; layout comes from `#previewer .preview .info`). */
|
||||
.preview-buttons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
.transcode-offer-message {
|
||||
margin: 1rem 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.transcode-session-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.transcode-session-list li {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.transcode-session-source {
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* this is just a workaround, the own plyr poster was hiding the video poster and showing black
|
||||
when it didn't loaded (somehow happens); but summarizing, this a bug of plyr, it also loads the poster image 2 times
|
||||
cuz it sets the URL on the html video tags and in their own */
|
||||
@@ -1438,24 +1428,6 @@ defineExpose({ destroy });
|
||||
pointer-events: none !important;
|
||||
}
|
||||
|
||||
.video-player-container {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #000;
|
||||
}
|
||||
|
||||
.video-loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 6;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
pointer-events: none;
|
||||
background: rgb(0 0 0 / 35%);
|
||||
}
|
||||
|
||||
/* Letterboxing and Plyr chrome */
|
||||
.video-player-container .plyr {
|
||||
background-color: #000;
|
||||
@@ -1528,31 +1500,4 @@ defineExpose({ destroy });
|
||||
background: transparent;
|
||||
line-height: 150%;
|
||||
}
|
||||
|
||||
/* Transcode offer (shown instead of the player; layout comes from `#previewer .preview .info`). */
|
||||
.preview-buttons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
.transcode-offer-message {
|
||||
margin: 1rem 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.transcode-session-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.transcode-session-list li {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.transcode-session-source {
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
@@ -5,7 +5,10 @@ import type { ShallowRef } from "vue";
|
||||
import Plyr from "plyr";
|
||||
import "plyr/dist/plyr.css";
|
||||
import "@/css/player.css";
|
||||
import { useI18n } from "@/i18n/index.ts";
|
||||
import { blockSeekOnInput } from "@/player/seekOnRelease.js";
|
||||
import { mutations, state } from "@/store/index.ts";
|
||||
import { globalVars } from "@/utils/constants.ts";
|
||||
import { getEndOfMediaAction, navigatePlaybackQueue } from "@/utils/playbackQueue.js";
|
||||
import { buildItemUrl, removeTrailingSlash } from "@/utils/url.js";
|
||||
|
||||
@@ -23,6 +26,7 @@ function decodePathSafely(path: string): string {
|
||||
}
|
||||
|
||||
type NativePlay = () => Promise<void> | void;
|
||||
type PlyrRuntimeOptions = Plyr.Options & { playsinline?: boolean; preload?: string };
|
||||
|
||||
/** Plyr keeps `media` and a no-arg `off()` at runtime but its typings omit them. */
|
||||
interface PlyrRuntime {
|
||||
@@ -43,7 +47,27 @@ export function resolveMountedFileKey(source?: string, path?: string): MountedFi
|
||||
};
|
||||
}
|
||||
|
||||
const PLYR_CONTROLS = [
|
||||
"play-large",
|
||||
"rewind",
|
||||
"play",
|
||||
"fast-forward",
|
||||
"progress",
|
||||
"current-time",
|
||||
"duration",
|
||||
"mute",
|
||||
"volume",
|
||||
"captions",
|
||||
"settings",
|
||||
"fullscreen",
|
||||
];
|
||||
const AUDIO_EXCLUDED_CONTROLS = ["play-large", "captions", "fullscreen"];
|
||||
|
||||
export type MediaKind = "audio" | "video";
|
||||
|
||||
interface MediaPlayerOptions {
|
||||
/** Decides the control set and whether fullscreen is available. */
|
||||
kind: MediaKind;
|
||||
player: ShallowRef<Plyr | null>;
|
||||
/** The <audio>/<video> element rendered by the component. */
|
||||
getMediaElement: () => HTMLMediaElement | null | undefined;
|
||||
@@ -61,12 +85,56 @@ interface MediaPlayerOptions {
|
||||
/** Creates, wires, stops and destroys the Plyr instance, and ends/advances playback. */
|
||||
export function useMediaPlayer(options: MediaPlayerOptions) {
|
||||
const { player } = options;
|
||||
const { t } = useI18n();
|
||||
let nativePlay: NativePlay | null = null;
|
||||
|
||||
function createPlayer(plyrOptions: Plyr.Options): Plyr | null {
|
||||
/** The Plyr options both players share; `createPlayer` merges the per-player extras over them. */
|
||||
function buildPlyrOptions(extra: Plyr.Options): PlyrRuntimeOptions {
|
||||
const isVideo = options.kind === "video";
|
||||
return {
|
||||
controls: isVideo ? [...PLYR_CONTROLS] : PLYR_CONTROLS.filter((id) => !AUDIO_EXCLUDED_CONTROLS.includes(id)),
|
||||
settings: ["captions", "quality", "speed", "playback", "loop"],
|
||||
speed: {
|
||||
selected: 1,
|
||||
options: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2],
|
||||
},
|
||||
disableContextMenu: true,
|
||||
seekTime: 10,
|
||||
hideControls: true,
|
||||
keyboard: { focused: true, global: true },
|
||||
loop: { active: false },
|
||||
blankVideo: "",
|
||||
muted: false,
|
||||
autoplay: false,
|
||||
playsinline: true,
|
||||
clickToPlay: false, // we manage this ourselves with the gestures, plyr has a issue where this doesn't work in mobile.
|
||||
resetOnEnd: false,
|
||||
preload: "none",
|
||||
fullscreen: {
|
||||
enabled: isVideo,
|
||||
fallback: true,
|
||||
iosNative: true,
|
||||
container: ".media-player",
|
||||
},
|
||||
iconUrl: `${globalVars.baseURL}public/static/img/plyr.svg`,
|
||||
listeners: {
|
||||
seek: blockSeekOnInput,
|
||||
},
|
||||
...extra,
|
||||
i18n: {
|
||||
playback: t("player.playbackMode"),
|
||||
loop: t("player.loop"),
|
||||
...extra.i18n,
|
||||
},
|
||||
tooltips: { controls: true, seek: true, ...extra.tooltips },
|
||||
};
|
||||
}
|
||||
|
||||
/** `extra` holds what only one player needs */
|
||||
function createPlayer(extra: Plyr.Options = {}): Plyr | null {
|
||||
const el = options.getMediaElement();
|
||||
if (!el) return null;
|
||||
player.value = new Plyr(el, plyrOptions);
|
||||
player.value = new Plyr(el, buildPlyrOptions(extra));
|
||||
return player.value;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@ import type { ShallowRef } from "vue";
|
||||
import type Plyr from "plyr";
|
||||
import { state } from "@/store/index.ts";
|
||||
import { globalVars } from "@/utils/constants.ts";
|
||||
import { ownsMediaSession } from "@/utils/mediaSessionOwnership.js";
|
||||
import { getNextItem, navigatePlaybackQueue } from "@/utils/playbackQueue.js";
|
||||
|
||||
/** Latest owner id handed out; only the instance holding it may touch the global Media Session. */
|
||||
let mediaSessionOwner = 0;
|
||||
|
||||
export interface MediaSessionInfo {
|
||||
@@ -20,7 +18,7 @@ export function useMediaSession(player: Readonly<ShallowRef<Plyr | null>>) {
|
||||
let ownerId = 0;
|
||||
|
||||
function owns(): boolean {
|
||||
return ownsMediaSession(ownerId, mediaSessionOwner);
|
||||
return ownerId > 0 && ownerId === mediaSessionOwner;
|
||||
}
|
||||
|
||||
function updateMediaSessionNavHandlers(): void {
|
||||
|
||||
@@ -81,6 +81,13 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (width <= 768px) {
|
||||
.plyr .plyr__control[data-plyr="rewind"],
|
||||
.plyr .plyr__control[data-plyr="fast-forward"] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Hide volume buttons on narrow screens to make more space */
|
||||
@media (width <= 550px) {
|
||||
.plyr__volume {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
/** True when this viewer instance currently owns the global Media Session slot. */
|
||||
export function ownsMediaSession(ownerId, globalOwner) {
|
||||
return ownerId > 0 && ownerId === globalOwner;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ownsMediaSession } from "./mediaSessionOwnership.js";
|
||||
|
||||
describe("ownsMediaSession", () => {
|
||||
it("rejects uninitialized viewers", () => {
|
||||
expect(ownsMediaSession(0, 0)).toBe(false);
|
||||
expect(ownsMediaSession(0, 2)).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts the active owner", () => {
|
||||
expect(ownsMediaSession(2, 2)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects stale owners after another viewer takes over", () => {
|
||||
expect(ownsMediaSession(1, 2)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -340,18 +340,7 @@ async function subtitles(): Promise<SubtitleSource[]> {
|
||||
|
||||
</script>
|
||||
|
||||
<!-- Classes owned by this view; the shared player styles live in src/css/player.css. -->
|
||||
<style>
|
||||
/* Background styles for the audio player */
|
||||
.media-background-dark {
|
||||
background: radial-gradient(#3b3b3b, black);
|
||||
}
|
||||
|
||||
.media-background-light {
|
||||
background: radial-gradient(#262626, #e2e2e2);
|
||||
}
|
||||
|
||||
/* Also used by VideoPlayer while it checks whether native playback is possible. */
|
||||
.av-preview-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -362,6 +351,14 @@ async function subtitles(): Promise<SubtitleSource[]> {
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
.media-background-dark {
|
||||
background: radial-gradient(#3b3b3b, black);
|
||||
}
|
||||
|
||||
.media-background-light {
|
||||
background: radial-gradient(#262626, #e2e2e2);
|
||||
}
|
||||
|
||||
.transition-loading {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
|
||||
Reference in new issue
Block a user