Skip to content

Commit 81f5c34

Browse files
authored
Handle webm infinity duration (#8)
* Handle webm infinity duration * Update package version
1 parent bd4945d commit 81f5c34

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# **react-audio-player-component**
2-
A audio player for React with a modern look and convenient usage
2+
A mobile-friendly audio player for React with a modern look and convenient usage.
33

44
## Installation
55
```sh

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-audio-player-component",
33
"private": false,
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"license": "MIT",
66
"author": "",
77
"repository": {

public/audios/audio.webm

117 KB
Binary file not shown.

src/components/AudioPlayer.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ const AudioPlayer: React.FC<
238238
audio.ontimeupdate = ontimeupdate;
239239
audio.onvolumechange = onvolumechange;
240240
audio.onwaiting = onwaiting;
241+
242+
audio.addEventListener("ended", onAudioEnded);
241243
setBlob(blob);
242244
return blob;
243245
})
@@ -248,8 +250,18 @@ const AudioPlayer: React.FC<
248250
setDuration(buffer.duration);
249251
});
250252
});
253+
254+
return () => {
255+
// clean up
256+
audio.removeEventListener("ended", onAudioEnded);
257+
};
251258
}, []);
252259

260+
const onAudioEnded = (): void => {
261+
setIsPlaying(false);
262+
setAudioTime(0);
263+
};
264+
253265
const playAudio = (): void => {
254266
if (!audio.src) return;
255267
if (audio.duration !== Infinity) setDuration(audio.duration);

src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AudioPlayer } from "./components/AudioPlayer";
55
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
66
<React.StrictMode>
77
<AudioPlayer
8-
src="audios/test.mp3"
8+
src="audios/audio.webm"
99
minimal={false}
1010
width={350}
1111
trackHeight={75}
@@ -20,7 +20,7 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
2020
skipDuration={2}
2121
showLoopOption={true}
2222
showVolumeControl={true}
23-
23+
onended={() => console.log("ENDED")}
2424
// seekBarColor="purple"
2525
// volumeControlColor="blue"
2626
// hideSeekBar={true}

0 commit comments

Comments
 (0)