Unga bunga

This commit is contained in:
Noah Knapp 2025-08-02 11:11:51 +02:00
parent 0f020d83d2
commit 0904b0e219
4 changed files with 47 additions and 10 deletions

View file

@ -0,0 +1,35 @@
import React, { useRef, useState } from "react";
const SingleAudioPlayer = ({ src }) => {
const audioRef = useRef(null);
const [isPlaying, setIsPlaying] = useState(false);
const togglePlay = () => {
const audio = audioRef.current;
if (!audio) return;
if (isPlaying) {
audio.pause();
} else {
audio.play().catch((e) => {
console.warn("Playback error:", e);
});
}
setIsPlaying(!isPlaying);
};
const handleEnded = () => {
setIsPlaying(false);
};
return (
<div style={{ display: "flex", alignItems: "center", gap: "1rem" }}>
<button onClick={togglePlay}>{isPlaying ? "Pause" : "Play"}</button>
<span>{src.split("/").pop()}</span>
<audio ref={audioRef} src={src} onEnded={handleEnded} />
</div>
);
};
export default SingleAudioPlayer;