fix(player): restore preserving html audio pitch

This commit is contained in:
Kendall Garner
2025-12-02 07:52:21 -08:00
parent f2b59d531b
commit bc5d0cf994
2 changed files with 16 additions and 2 deletions
@@ -1,6 +1,6 @@
import type { RefObject } from 'react';
import { useImperativeHandle, useRef, useState } from 'react';
import { useEffect, useImperativeHandle, useRef, useState } from 'react';
import ReactPlayer from 'react-player';
import { AudioPlayer, PlayerOnProgressProps } from '/@/renderer/features/player/audio-player/types';
@@ -32,6 +32,7 @@ interface WebPlayerEngineProps {
playerNum: number;
playerRef: RefObject<null | WebPlayerEngineHandle>;
playerStatus: PlayerStatus;
preservesPitch: boolean;
speed?: number;
src1: string | undefined;
src2: string | undefined;
@@ -59,6 +60,7 @@ export const WebPlayerEngine = (props: WebPlayerEngineProps) => {
playerNum,
playerRef,
playerStatus,
preservesPitch,
speed,
src1,
src2,
@@ -149,6 +151,17 @@ export const WebPlayerEngine = (props: WebPlayerEngineProps) => {
};
};
useEffect(() => {
const player1 = player1Ref.current?.getInternalPlayer();
if (player1) {
player1.preservesPitch = preservesPitch;
}
const player2 = player2Ref.current?.getInternalPlayer();
if (player2) {
player2.preservesPitch = preservesPitch;
}
}, [preservesPitch]);
return (
<div id="web-player-engine" style={{ display: 'none' }}>
<ReactPlayer
@@ -36,7 +36,7 @@ export function WebPlayer() {
const { crossfadeDuration, crossfadeStyle, speed, transitionType } = usePlayerProperties();
const isMuted = usePlayerMuted();
const volume = usePlayerVolume();
const { transcode } = usePlaybackSettings();
const { preservePitch, transcode } = usePlaybackSettings();
const [localPlayerStatus, setLocalPlayerStatus] = useState<PlayerStatus>(status);
const [isTransitioning, setIsTransitioning] = useState<boolean | string>(false);
@@ -432,6 +432,7 @@ export function WebPlayer() {
playerNum={num}
playerRef={playerRef}
playerStatus={localPlayerStatus}
preservesPitch={preservePitch}
speed={speed}
src1={player1Url}
src2={player2Url}