fix: preserve pitch toggle now works for MPV backend (#2297)

* fix: preserve pitch toggle now works for MPV backend

* update docs

---------

Co-authored-by: Kendall Garner <17521368+kgarner7@users.noreply.github.com>
This commit is contained in:
Sekiryl
2026-07-31 10:21:05 +05:30
committed by GitHub
parent 8b7615bebb
commit a26b8c4839
2 changed files with 20 additions and 3 deletions
@@ -27,6 +27,7 @@ interface MpvPlayerEngineProps {
onProgress: (e: PlayerOnProgressProps) => void;
playerRef: RefObject<MpvPlayerEngineHandle | null>;
playerStatus: PlayerStatus;
preservePitch?: boolean;
speed?: number;
volume: number;
}
@@ -45,6 +46,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
onProgress,
playerRef,
playerStatus,
preservePitch,
speed,
volume,
} = props;
@@ -107,6 +109,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
// Initialize mpv with fresh state
const properties: Record<string, any> = {
...getMpvProperties(mpvProperties),
'audio-pitch-correction': preservePitch === false ? 'no' : 'yes',
speed: speed,
volume: volume,
};
@@ -161,8 +164,8 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
isInitializedRef.current = false;
hasPopulatedQueueRef.current = false;
};
// Note: volume, speed, and transcode are intentionally not in dependencies.
// Volume and speed changes are handled by separate useEffects below to avoid
// Note: volume, speed, preservePitch, and transcode are intentionally not in dependencies.
// Volume speed, and preservePitch changes are handled by separate useEffects below to avoid
// reinitializing the entire player. Transcode changes are handled by queue
// update callbacks in usePlayerEvents.
// reloadTrigger is included to allow manual reload via MPV_RELOAD event.
@@ -204,6 +207,19 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
mpvPlayer.setProperties({ speed });
}, [speed]);
// Update pitch correction status
useEffect(() => {
if (!mpvPlayer) {
return;
}
if (preservePitch === false) {
mpvPlayer.setProperties({ 'audio-pitch-correction': 'no' });
} else {
mpvPlayer.setProperties({ 'audio-pitch-correction': 'yes' });
}
}, [preservePitch]);
// Handle play/pause status
useEffect(() => {
if (!mpvPlayer) {
@@ -28,7 +28,7 @@ export function MpvPlayer() {
const { speed } = usePlayerProperties();
const isMuted = usePlayerMuted();
const volume = usePlayerVolume();
const { audioFadeOnStatusChange } = usePlaybackSettings();
const { audioFadeOnStatusChange, preservePitch } = usePlaybackSettings();
const [localPlayerStatus, setLocalPlayerStatus] = useState<PlayerStatus>(status);
const [isTransitioning, setIsTransitioning] = useState(false);
@@ -180,6 +180,7 @@ export function MpvPlayer() {
onProgress={onProgress}
playerRef={playerRef}
playerStatus={localPlayerStatus}
preservePitch={preservePitch}
speed={speed}
volume={volume}
/>