-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.jsx
35 lines (31 loc) · 905 Bytes
/
Player.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable jsx-a11y/media-has-caption */
import React, { useRef, useEffect } from 'react';
const Player = ({ activeSong, isPlaying, volume, seekTime, onEnded, onTimeUpdate, onLoadedData, repeat }) => {
const ref = useRef(null);
// eslint-disable-next-line no-unused-expressions
if (ref.current) {
if (isPlaying) {
ref.current.play();
} else {
ref.current.pause();
}
}
useEffect(() => {
ref.current.volume = volume;
}, [volume]);
// updates audio element only on seekTime change (and not on each rerender):
useEffect(() => {
ref.current.currentTime = seekTime;
}, [seekTime]);
return (
<audio
src={activeSong?.hub?.actions[1]?.uri}
ref={ref}
loop={repeat}
onEnded={onEnded}
onTimeUpdate={onTimeUpdate}
onLoadedData={onLoadedData}
/>
);
};
export default Player;