|
|
|
@ -42,14 +42,15 @@ export default function HomePage() { |
|
|
|
|
//记录音频播放模式
|
|
|
|
|
//0 列表循环
|
|
|
|
|
//1 单曲循环
|
|
|
|
|
//2 定时播放
|
|
|
|
|
const [playMode, setplayMode] = useState<number>(0) |
|
|
|
|
|
|
|
|
|
// 定时播放
|
|
|
|
|
const [playTimer, setPlayTimer] = useState<number>(0) |
|
|
|
|
|
|
|
|
|
//控制定时播放弹窗
|
|
|
|
|
const [isShowRg, setisShowRg] = useState(false) |
|
|
|
|
|
|
|
|
|
const [timerId, setTimerId] = useState<null | ReturnType<typeof setInterval>>(null); |
|
|
|
|
const [seconds, setSeconds] = useState(0); |
|
|
|
|
const [selectedDuration, setSelectedDuration] = useState(600); // 默认选择600秒
|
|
|
|
|
|
|
|
|
|
//记录prdtId
|
|
|
|
@ -111,15 +112,14 @@ export default function HomePage() { |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
const startTimer = () => { |
|
|
|
|
if (timerId !== null) return; // 如果已经有计时器在运行,则返回
|
|
|
|
|
let id = setInterval(() => { |
|
|
|
|
setSeconds(prevSeconds => prevSeconds + 1); |
|
|
|
|
if (seconds >= selectedDuration - 1) { |
|
|
|
|
videoRef.current = null; |
|
|
|
|
clearInterval(id); |
|
|
|
|
setTimerId(null); |
|
|
|
|
} |
|
|
|
|
}, 1000); |
|
|
|
|
stopTimer() |
|
|
|
|
const id = setTimeout(() => { |
|
|
|
|
setisPlay(false) |
|
|
|
|
setPlayTimer(0) |
|
|
|
|
clearTimeout(id); |
|
|
|
|
setTimerId(null); |
|
|
|
|
// }, playTimer * 1000 * 3);
|
|
|
|
|
}, playTimer * 1000 * 60 * 10); |
|
|
|
|
setTimerId(id); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -127,29 +127,12 @@ export default function HomePage() { |
|
|
|
|
if (timerId !== null) { |
|
|
|
|
clearInterval(timerId); |
|
|
|
|
setTimerId(null); |
|
|
|
|
setSeconds(0); // 重置秒数
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
return () => { |
|
|
|
|
if (timerId !== null) { |
|
|
|
|
clearInterval(timerId); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
}, [timerId]); // 只有当 timerId 发生变化时才执行
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if(playMode > 2){ |
|
|
|
|
if(selectedDuration !== (playMode - 2) * 600){ |
|
|
|
|
stopTimer() |
|
|
|
|
setSelectedDuration((playMode - 2) * 600) |
|
|
|
|
startTimer() |
|
|
|
|
} |
|
|
|
|
}else if(playMode === 2){ |
|
|
|
|
stopTimer() |
|
|
|
|
} |
|
|
|
|
}, [playMode]) |
|
|
|
|
playTimer && startTimer() |
|
|
|
|
}, [playTimer]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
isPlay && setPlayed(true) |
|
|
|
@ -160,14 +143,14 @@ export default function HomePage() { |
|
|
|
|
const audio = videoRef.current; |
|
|
|
|
|
|
|
|
|
if (isPlay) { |
|
|
|
|
if(currentTime !== 0){ |
|
|
|
|
if (currentTime !== 0) { |
|
|
|
|
if(isFirst){ |
|
|
|
|
console.log('第一次播放') |
|
|
|
|
const hls = new HLS.default(); // 使用 HLS.js
|
|
|
|
|
console.log('加载HLS流地址=>', testMusic) |
|
|
|
|
hls.loadSource(testMusic); // 加载 HLS 流地址
|
|
|
|
|
hls.attachMedia(audio); // 关联 media 元素
|
|
|
|
|
hls.on(HLS.Events.MANIFEST_PARSED, function() { |
|
|
|
|
hls.on(HLS.Events.MANIFEST_PARSED, function () { |
|
|
|
|
audio.currentTime = currentTime |
|
|
|
|
audio.play() |
|
|
|
|
setisFirst(false) |
|
|
|
@ -184,6 +167,7 @@ export default function HomePage() { |
|
|
|
|
hls.attachMedia(audio); // 关联 media 元素
|
|
|
|
|
hls.on(HLS.Events.MANIFEST_PARSED, function() { |
|
|
|
|
audio.play(); // 开始播放
|
|
|
|
|
setisFirst(false) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -205,8 +189,6 @@ export default function HomePage() { |
|
|
|
|
} |
|
|
|
|
}else if(playMode === 1){ |
|
|
|
|
|
|
|
|
|
}else if(playMode === 2){ |
|
|
|
|
setplayMode(0) |
|
|
|
|
} |
|
|
|
|
audio.currentTime = 0 |
|
|
|
|
}) |
|
|
|
@ -217,7 +199,6 @@ export default function HomePage() { |
|
|
|
|
|
|
|
|
|
audio.addEventListener('pause', () => { |
|
|
|
|
setcurrentTime(audio.currentTime) |
|
|
|
|
setisPlay(false) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
audio.addEventListener('play', () => { |
|
|
|
@ -287,12 +268,6 @@ export default function HomePage() { |
|
|
|
|
|
|
|
|
|
}, [listIndex]) |
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
|
if(playMode > 1){ |
|
|
|
|
setisShowRg(true) |
|
|
|
|
} |
|
|
|
|
}, [playMode]) |
|
|
|
|
|
|
|
|
|
const handleClickList = () => { |
|
|
|
|
setisShowList(true) |
|
|
|
|
} |
|
|
|
@ -307,7 +282,15 @@ export default function HomePage() { |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div className='audio_progress_bar'> |
|
|
|
|
<div className='audio_title'>{MusicDesc.PrdtTitle}</div> |
|
|
|
|
<div className="audio_title_wrap"> |
|
|
|
|
<div className='audio_title'>{MusicDesc.PrdtTitle}</div> |
|
|
|
|
|
|
|
|
|
<img |
|
|
|
|
className='audio_btn' |
|
|
|
|
src='https://oss.jm-kid.com/wx_5colorflower/assets/regularPlay.png' |
|
|
|
|
onClick={() => setisShowRg(true)} |
|
|
|
|
></img> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<ConfigProvider |
|
|
|
|
theme={{ |
|
|
|
@ -363,16 +346,8 @@ export default function HomePage() { |
|
|
|
|
<div className='audio_operate'> |
|
|
|
|
<img |
|
|
|
|
className='audio_operate_btn0' |
|
|
|
|
src={playMode === 0 ? 'https://oss.jm-kid.com/wx_5colorflower/assets/listPlay.png' : playMode === 1 ? 'https://oss.jm-kid.com/wx_5colorflower/assets/cyclePlay.png' : 'https://oss.jm-kid.com/wx_5colorflower/assets/regularPlay.png'} |
|
|
|
|
onClick={() => { |
|
|
|
|
if(playMode === 0){ |
|
|
|
|
setplayMode(1) |
|
|
|
|
}else if(playMode === 1){ |
|
|
|
|
setplayMode(2) |
|
|
|
|
}else{ |
|
|
|
|
setplayMode(0) |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
src={playMode === 0 ? 'https://oss.jm-kid.com/wx_5colorflower/assets/listPlay.png' : 'https://oss.jm-kid.com/wx_5colorflower/assets/cyclePlay.png'} |
|
|
|
|
onClick={() => setplayMode(playMode ? 0 : 1)} |
|
|
|
|
></img> |
|
|
|
|
<img
|
|
|
|
|
className='audio_operate_btn0' |
|
|
|
@ -424,8 +399,8 @@ export default function HomePage() { |
|
|
|
|
<RgupHalfScreen |
|
|
|
|
visible={isShowRg} |
|
|
|
|
onClose={() => setisShowRg(false)} |
|
|
|
|
type={playMode} |
|
|
|
|
setType={setplayMode} |
|
|
|
|
playTimer={playTimer} |
|
|
|
|
setPlayTimer={setPlayTimer} |
|
|
|
|
></RgupHalfScreen> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|