This commit is contained in:
Luke Berndt
2024-09-16 21:47:46 -04:00
parent 1b6563c1a8
commit fb823ab46d
5 changed files with 302 additions and 101 deletions

View File

@@ -24,6 +24,7 @@
"@visx/scale": "^3.0.0", "@visx/scale": "^3.0.0",
"@visx/shape": "^3.0.0", "@visx/shape": "^3.0.0",
"@visx/tooltip": "^3.1.2", "@visx/tooltip": "^3.1.2",
"@wavesurfer/react": "^1.0.7",
"axios": "1.2.1", "axios": "1.2.1",
"d3-array": "^3.2.3", "d3-array": "^3.2.3",
"d3-time-format": "^4.1.0", "d3-time-format": "^4.1.0",
@@ -5783,6 +5784,15 @@
"react-dom": "^16.8.0-0 || ^17.0.0-0 || ^18.0.0-0" "react-dom": "^16.8.0-0 || ^17.0.0-0 || ^18.0.0-0"
} }
}, },
"node_modules/@wavesurfer/react": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@wavesurfer/react/-/react-1.0.7.tgz",
"integrity": "sha512-Bw2rd2zqVL1ERy8N9mciacbQW3N5Gn9oRjhq3kjqgtLeE8a1WSTU+4kU0E37541jf432eNZ8lNzuodFFSiNccw==",
"peerDependencies": {
"react": "^18.2.0",
"wavesurfer.js": ">=7.7.14"
}
},
"node_modules/@webassemblyjs/ast": { "node_modules/@webassemblyjs/ast": {
"version": "1.11.1", "version": "1.11.1",
"resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz",
@@ -17748,6 +17758,12 @@
"node": ">=10.13.0" "node": ">=10.13.0"
} }
}, },
"node_modules/wavesurfer.js": {
"version": "7.8.6",
"resolved": "https://registry.npmjs.org/wavesurfer.js/-/wavesurfer.js-7.8.6.tgz",
"integrity": "sha512-EDexkMwkkQBTWruhfWQRkTtvRggtKFTPuJX/oZ5wbIZEfyww9EBeLr2mtkxzA1S8TlWPx6adY5WyjOlNYNyHSg==",
"peer": true
},
"node_modules/wbuf": { "node_modules/wbuf": {
"version": "1.7.3", "version": "1.7.3",
"resolved": "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz", "resolved": "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz",

View File

@@ -19,6 +19,7 @@
"@visx/scale": "^3.0.0", "@visx/scale": "^3.0.0",
"@visx/shape": "^3.0.0", "@visx/shape": "^3.0.0",
"@visx/tooltip": "^3.1.2", "@visx/tooltip": "^3.1.2",
"@wavesurfer/react": "^1.0.7",
"axios": "1.2.1", "axios": "1.2.1",
"d3-array": "^3.2.3", "d3-array": "^3.2.3",
"d3-time-format": "^4.1.0", "d3-time-format": "^4.1.0",

View File

@@ -6,16 +6,190 @@ import {
Label Label
} from "semantic-ui-react"; } from "semantic-ui-react";
import ReactAudioPlayer from 'react-audio-player' import ReactAudioPlayer from 'react-audio-player'
import WavesurferPlayer from '@wavesurfer/react'
import { is } from "date-fns/locale";
const MediaPlayer = (props) => { const MediaPlayer = (props) => {
const call = props.call;
const [sourceIndex, setSourceIndex] = useState(0);
const [wavesurfer, setWavesurfer] = useState(null)
const [isPlaying, setIsPlaying] = useState(false)
const [playTime, setPlayTime] = useState(0);
const playSilence = props.playSilence;
const onReady = (ws) => {
setWavesurfer(ws)
setIsPlaying(false)
}
const onPlayPause = () => {
wavesurfer && wavesurfer.playPause()
}
useEffect(() => {
//const audio = audioRef.current.audioEl.current;
setSourceIndex(0);
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: "Waiting for Call...",
album: 'OpenMHz',
artwork: [
{ src: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
{ src: '/android-chrome-192x192.png', sizes: '192x192', type: 'image/png' },
{ src: '/android-chrome-192x192.png', sizes: '512x512', type: 'image/png' },
]
});
}
if (wavesurfer) {
var reader = new FileReader();
reader.onload = function (evt) {
// Create a Blob providing as first argument a typed array with the file buffer
var blob = new window.Blob([new Uint8Array(evt.target.result)]);
// Load the blob into Wavesurfer
wavesurfer.loadBlob(blob);
};
reader.onerror = function (evt) {
console.error("An error ocurred reading the file: ", evt);
};
// Read File as an ArrayBuffer
reader.readAsArrayBuffer("data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4Ljc2LjEwMAAAAAAAAAAAAAAA/+M4wAAAAAAAAAAAAEluZm8AAAAPAAAAAwAAAbAAqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV////////////////////////////////////////////AAAAAExhdmM1OC4xMwAAAAAAAAAAAAAAACQDkAAAAAAAAAGw9wrNaQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/+MYxAAAAANIAAAAAExBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV/+MYxDsAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV/+MYxHYAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV");
}
/*const playPromise = audio.play();
// In browsers that don’t yet support this functionality,
// playPromise won’t be defined.
if (playPromise !== undefined) {
playPromise.then(function () {
}).catch(function (error) {
console.log("Automatic playback failed: " + error);
// Show a UI element to let the user manually start playback.
});
} else {
audio.src = false;
}*/
}, [playSilence]);
/*
useEffect(() => {
const audio = audioRef.current.audioEl.current;
const onEnded = props.onEnded;
setSourceIndex(0);
if (call ) {
audio.src = call.url;
const playPromise = audio.play();
// In browsers that don’t yet support this functionality,
// playPromise won’t be defined.
if (playPromise !== undefined) {
playPromise.then(function () {
}).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;
}
}
}, [call]);*/
const updatePlayProgress = () => {
if (wavesurfer && wavesurfer.isPlaying()) {
var totalTime = wavesurfer.getDuration(),
currentTime = wavesurfer.getCurrentTime(),
remainingTime = totalTime - currentTime;
if (!isPlaying) {
setIsPlaying(true);
}
//console.log("totalTime: " + totalTime + " currentTime: " + currentTime + " remainingTime: " + remainingTime);
// this checks to see if it should display the next Source ID
if (call && ((call.srcList.length - 1) >= (sourceIndex + 1)) && (currentTime > call.srcList[sourceIndex + 1].pos)) {
setSourceIndex(sourceIndex + 1);
console.log("sourceIndex: " + sourceIndex);
}
setPlayTime(Math.floor(currentTime));
}
}
let playEnabled = { "disabled": true }
let sourceId = "-";
if (call) {
if (call.srcList.length > sourceIndex) {
sourceId = call.srcList[sourceIndex].src;
}
playEnabled = {};
}
return (
<Menu.Menu>
<Menu.Item onClick={onPlayPause} >
{
isPlaying
? (<Icon name="pause" />)
: (<Icon name="play" />)
}
</Menu.Item>
<Menu.Item>
<WavesurferPlayer
autoplay={true}
height={25}
width={300}
waveColor="#E81B39"
url={call.url}
onReady={onReady}
onPlay={() => setIsPlaying(true)}
onPause={() => setIsPlaying(false)}
onAudioprocess={updatePlayProgress}
onFinish={props.onEnded}
/>
</Menu.Item>
<Menu.Item>
<Label color="black">
{playTime}
Sec
</Label>
<Label color="black" className="desktop-only">
{sourceId}
</Label>
</Menu.Item>
</Menu.Menu>
)
/*
const audioRef = React.createRef(); const audioRef = React.createRef();
const [sourceIndex, setSourceIndex] = useState(0); const [sourceIndex, setSourceIndex] = useState(0);
const [playProgress, setPlayProgress] = useState(0); const [playProgress, setPlayProgress] = useState(0);
const [playTime, setPlayTime] = useState(0); const [playTime, setPlayTime] = useState(0);
const [isPlaying, setIsPlaying] = useState(false);
const parentHandlePlayPause = props.onPlayPause const parentHandlePlayPause = props.onPlayPause
const playSilence = props.playSilence; const playSilence = props.playSilence;
@@ -158,7 +332,7 @@ const MediaPlayer = (props) => {
</Menu.Item> </Menu.Item>
</Menu.Menu> </Menu.Menu>
) )*/
} }
export default MediaPlayer; export default MediaPlayer;

View File

@@ -3226,6 +3226,11 @@
prop-types "^15.5.10" prop-types "^15.5.10"
react-use-measure "^2.0.4" react-use-measure "^2.0.4"
"@wavesurfer/react@^1.0.7":
version "1.0.7"
resolved "https://registry.npmjs.org/@wavesurfer/react/-/react-1.0.7.tgz"
integrity sha512-Bw2rd2zqVL1ERy8N9mciacbQW3N5Gn9oRjhq3kjqgtLeE8a1WSTU+4kU0E37541jf432eNZ8lNzuodFFSiNccw==
"@webassemblyjs/ast@1.11.1": "@webassemblyjs/ast@1.11.1":
version "1.11.1" version "1.11.1"
resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz" resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz"
@@ -10358,6 +10363,11 @@ watchpack@^2.4.0:
glob-to-regexp "^0.4.1" glob-to-regexp "^0.4.1"
graceful-fs "^4.1.2" graceful-fs "^4.1.2"
wavesurfer.js@>=7.7.14:
version "7.8.6"
resolved "https://registry.npmjs.org/wavesurfer.js/-/wavesurfer.js-7.8.6.tgz"
integrity sha512-EDexkMwkkQBTWruhfWQRkTtvRggtKFTPuJX/oZ5wbIZEfyww9EBeLr2mtkxzA1S8TlWPx6adY5WyjOlNYNyHSg==
wbuf@^1.1.0, wbuf@^1.7.3: wbuf@^1.1.0, wbuf@^1.7.3:
version "1.7.3" version "1.7.3"
resolved "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz" resolved "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz"