Skip to content

Commit

Permalink
improve audio buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mebtte committed Sep 17, 2023
1 parent e3f319d commit 0148f51
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion apps/pwa/src/pages/player/use_audio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,22 @@ function useAudio({ queueMusic }: { queueMusic?: QueueMusic }) {
}
}, [audio]);

/**
* sometimes progress event not trigger when percent === 1
* @author mebtte<hi@mebtte.com>
*/
useEffect(() => {
if (audio && bufferedPercent !== 1) {
const timer = window.setInterval(() => {
setBufferedPercent(audio.getBufferedPercent());
}, 1000 * 5);
return () => window.clearInterval(timer);
}
}, [audio, bufferedPercent]);

/**
* reset all data
* make sure this on last of hooks
* make sure this keep last of hooks
* @author mebtte<hi@mebtte.com>
*/
useEffect(() => {
Expand Down

0 comments on commit 0148f51

Please sign in to comment.