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; onProgress: (e: PlayerOnProgressProps) => void;
playerRef: RefObject<MpvPlayerEngineHandle | null>; playerRef: RefObject<MpvPlayerEngineHandle | null>;
playerStatus: PlayerStatus; playerStatus: PlayerStatus;
preservePitch?: boolean;
speed?: number; speed?: number;
volume: number; volume: number;
} }
@@ -45,6 +46,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
onProgress, onProgress,
playerRef, playerRef,
playerStatus, playerStatus,
preservePitch,
speed, speed,
volume, volume,
} = props; } = props;
@@ -107,6 +109,7 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
// Initialize mpv with fresh state // Initialize mpv with fresh state
const properties: Record<string, any> = { const properties: Record<string, any> = {
...getMpvProperties(mpvProperties), ...getMpvProperties(mpvProperties),
'audio-pitch-correction': preservePitch === false ? 'no' : 'yes',
speed: speed, speed: speed,
volume: volume, volume: volume,
}; };
@@ -161,8 +164,8 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
isInitializedRef.current = false; isInitializedRef.current = false;
hasPopulatedQueueRef.current = false; hasPopulatedQueueRef.current = false;
}; };
// Note: volume, speed, and transcode are intentionally not in dependencies. // Note: volume, speed, preservePitch, and transcode are intentionally not in dependencies.
// Volume and speed changes are handled by separate useEffects below to avoid // Volume speed, and preservePitch changes are handled by separate useEffects below to avoid
// reinitializing the entire player. Transcode changes are handled by queue // reinitializing the entire player. Transcode changes are handled by queue
// update callbacks in usePlayerEvents. // update callbacks in usePlayerEvents.
// reloadTrigger is included to allow manual reload via MPV_RELOAD event. // reloadTrigger is included to allow manual reload via MPV_RELOAD event.
@@ -204,6 +207,19 @@ export const MpvPlayerEngine = (props: MpvPlayerEngineProps) => {
mpvPlayer.setProperties({ speed }); mpvPlayer.setProperties({ speed });
}, [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 // Handle play/pause status
useEffect(() => { useEffect(() => {
if (!mpvPlayer) { if (!mpvPlayer) {
@@ -28,7 +28,7 @@ export function MpvPlayer() {
const { speed } = usePlayerProperties(); const { speed } = usePlayerProperties();
const isMuted = usePlayerMuted(); const isMuted = usePlayerMuted();
const volume = usePlayerVolume(); const volume = usePlayerVolume();
const { audioFadeOnStatusChange } = usePlaybackSettings(); const { audioFadeOnStatusChange, preservePitch } = usePlaybackSettings();
const [localPlayerStatus, setLocalPlayerStatus] = useState<PlayerStatus>(status); const [localPlayerStatus, setLocalPlayerStatus] = useState<PlayerStatus>(status);
const [isTransitioning, setIsTransitioning] = useState(false); const [isTransitioning, setIsTransitioning] = useState(false);
@@ -180,6 +180,7 @@ export function MpvPlayer() {
onProgress={onProgress} onProgress={onProgress}
playerRef={playerRef} playerRef={playerRef}
playerStatus={localPlayerStatus} playerStatus={localPlayerStatus}
preservePitch={preservePitch}
speed={speed} speed={speed}
volume={volume} volume={volume}
/> />