still not fixed

This commit is contained in:
Luke Berndt
2024-10-02 21:33:38 -04:00
parent f7667cf1b5
commit 795bb3a069

View File

@@ -23,8 +23,9 @@ import "./MediaPlayer.css";
const MediaPlayer = (props) => { const MediaPlayer = (props) => {
const containerRef = useRef(null) const containerRef = useRef(null)
const audioRef = React.createRef(); const audioRef = useRef(new Audio());
const call = props.call; const call = props.call;
const [sourceIndex, setSourceIndex] = useState(0); const [sourceIndex, setSourceIndex] = useState(0);
//const [wavesurfer, setWavesurfer] = useState(null) //const [wavesurfer, setWavesurfer] = useState(null)
@@ -59,8 +60,9 @@ const MediaPlayer = (props) => {
barGap: 3, barGap: 3,
barRadius: 6, barRadius: 6,
plugins: plugins, plugins: plugins,
backend: 'MediaElementWebAudio',
responsive: true, responsive: true,
media: audioRef.current,
backend: 'MediaElement',
//autoplay: true, //autoplay: true,
}) })
@@ -71,7 +73,8 @@ const MediaPlayer = (props) => {
// }, [wavesurfer]) // }, [wavesurfer])
useEffect(() => { useEffect(() => {
setSourceIndex(0); setSourceIndex(0);
if (audioRef.current) {
const audio = audioRef.current;
if ('mediaSession' in navigator) { if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({ navigator.mediaSession.metadata = new MediaMetadata({
title: "Waiting for Call...", title: "Waiting for Call...",
@@ -84,9 +87,9 @@ const MediaPlayer = (props) => {
}); });
} }
wavesurfer && wavesurfer.load("/silence.m4a"); audio.src = "/silence.m4a"; //wavesurfer.load("/silence.m4a");
regionsPlugin.clearRegions(); regionsPlugin.clearRegions();
}
// // In browsers that don’t yet support this functionality, // // In browsers that don’t yet support this functionality,
// // playPromise won’t be defined. // // playPromise won’t be defined.
// if (playPromise !== undefined) { // if (playPromise !== undefined) {
@@ -108,31 +111,54 @@ const MediaPlayer = (props) => {
} }
}, [hasFinished]); }, [hasFinished]);
useEffect(() => {
const readyState = audioRef.current.readyState;
const audio = audioRef.current;
if (readyState === 4) {
// wavesurfer.load(audioRef.current.src);
}
console.log("readyState: " + readyState);
}, [audioRef.current.readyState]);
useEffect(() => { useEffect(() => {
if (call && wavesurfer) { if (call && wavesurfer) {
wavesurfer.load(call.url); const audio = audioRef.current;
if (audio) {
audio.src = call.url;
audio.load();
const playPromise = audio.play();
// In browsers that don’t yet support this functionality,
// playPromise won’t be defined.
if (playPromise !== undefined) {
playPromise.then(function () {
console.log("clearRegions");
regionsPlugin.clearRegions();
call.srcList.forEach(src => {
regionsPlugin.addRegion({
start: src.pos,
color: "rgba(128, 128, 128, 1.0)",
drag: false,
resize: false
});
});
}).catch(function (error) {
console.log("Automatic playback failed: " + error);
//handlePause();
//onEnded();
// Show a UI element to let the user manually start playback.
});
} else {
audio.src = false;
}
}
} }
setSourceIndex(0); setSourceIndex(0);
}, [call]); }, [call]);
useEffect(() => {
if (isReady && wavesurfer) {
wavesurfer.play()
//regionsPlugin.clearRegions();
if (call) {
// call.srcList.forEach(src => {
// regionsPlugin.addRegion({
// start: src.pos,
// color: "rgba(128, 128, 128, 1.0)",
// drag: false,
// resize: false
// });
// });
}
}
}, [isReady]);
useEffect(() => { useEffect(() => {