问题描述
iam使用django开发音乐站点并做出反应,您可以保存您的歌曲和播放列表,我想保存刷新之前正在播放的播放列表... iam仅保存当前歌曲(名称,文件,id,图像)在本地存储中 所以问题是,将所有播放列表保存在本地存储中会不会有问题?还是有另一种处理方式?
const handleEnd=()=>{
let songId=props.currentSong.id || localStorage.getItem('id')
let currentIndex=props.songs.findIndex(track=>track.id===songId)
if (props.songs[currentIndex] === props.songs.length-1 ){
currentIndex=0
props.setCurrentSong(props.songs[currentIndex].id)
}
else{
const next=currentIndex+1
if(next >= props.songs.length-1){
currentIndex=-1
}
else{
props.setCurrentSong(props.songs[next].id)
}
}
}
const handleNextPrev=(np)=>{
let songId=props.currentSong.id || localStorage.getItem('id')
let currentIndex=props.songs.findIndex(song=>song.id===songId)
if(np==='next')
{
if (currentIndex === props.songs.length-1 )
{
currentIndex=0
props.setCurrentSong(props.songs[currentIndex].id)
}else{
const next=currentIndex+1
props.setCurrentSong(props.songs[next].id)
}
}
else if(np==='prev')
{
if (currentIndex === 0 )
{
console.log(currentIndex);
props.setCurrentSong(props.songs[props.songs.length-1].id)
}
else
{
console.log(currentIndex);
const previous=currentIndex-1
props.setCurrentSong(props.songs[previous].id)
}
}
}
如果刷新,我会使用这两个功能在播放列表中循环播放,我会丢失所有数据,但只会丢失当前曲目
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)