|
|
|
@ -121,13 +121,15 @@ export default function AudioPlayer({
|
|
|
|
|
|
|
|
|
|
// 监听音频进度
|
|
|
|
|
const listenTimeUpdate = () => {
|
|
|
|
|
const currentTime = Math.ceil(audioRef.current.currentTime) ?? 0;
|
|
|
|
|
|
|
|
|
|
// 完成播放
|
|
|
|
|
if (audioRef.current.ended) {
|
|
|
|
|
if (audioRef.current.ended || currentTime >= audioRef.current.duration) {
|
|
|
|
|
handleSwitchAudio(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isDrag.current) {
|
|
|
|
|
setTrackProgress(audioRef.current.currentTime);
|
|
|
|
|
setTrackProgress(currentTime);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -187,7 +189,6 @@ export default function AudioPlayer({
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
|
audioRef.current.oncanplaythrough = resolve;
|
|
|
|
|
audioRef.current.onerror = reject;
|
|
|
|
|
audioRef.current.addEventListener('timeupdate', listenTimeUpdate);
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error downloading and playing audio:', error);
|
|
|
|
@ -195,9 +196,10 @@ export default function AudioPlayer({
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const initAudioMeta = () => {
|
|
|
|
|
setMediaSession(); // 设置 MediaSession
|
|
|
|
|
handleSetVolume(volume); // 设置音量
|
|
|
|
|
setDuration(audioRef.current.duration); // 设置音频时长
|
|
|
|
|
setMediaSession();
|
|
|
|
|
handleSetVolume(volume);
|
|
|
|
|
setDuration(audioRef.current.duration);
|
|
|
|
|
audioRef.current.addEventListener('timeupdate', listenTimeUpdate);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const switchNewAudio = async () => {
|
|
|
|
|