43 lines
1001 B
TypeScript
43 lines
1001 B
TypeScript
import { VoiceOverMode } from "@/types/voiceOverMode";
|
|
import { useEffect, useRef } from "react";
|
|
|
|
export type VoiceOverSource = {
|
|
src: string;
|
|
type: string;
|
|
};
|
|
|
|
interface VoiceOverProps {
|
|
sources: VoiceOverSource[];
|
|
voiceOverMode: VoiceOverMode;
|
|
}
|
|
|
|
export default function VoiceOver({ sources, voiceOverMode }: VoiceOverProps) {
|
|
const audioRef = useRef<HTMLAudioElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
const audio = audioRef.current;
|
|
if (!audio) return;
|
|
|
|
if (voiceOverMode === "on") {
|
|
audio.play().catch((error) => {
|
|
console.warn("Audio playback prevented:", error);
|
|
});
|
|
} else {
|
|
audio.pause();
|
|
audio.currentTime = 0;
|
|
}
|
|
}, [voiceOverMode]);
|
|
|
|
return (
|
|
<audio
|
|
ref={audioRef}
|
|
controlsList="nodownload nofullscreen"
|
|
preload="auto"
|
|
playsInline={true}
|
|
>
|
|
{sources.map((source, index) => (
|
|
<source key={source.src || index} src={source.src} type={source.type} />
|
|
))}
|
|
</audio>
|
|
);
|
|
} |