Voiceovers, Hints
This commit is contained in:
1 parent
83888a21e1
commit
43e02d5e08
63 files changed
+103
-23
No files matched your search
@@ -0,0 +1,43 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user