Skip to content

Commit

Permalink
播放完毕重置缓存path
Browse files Browse the repository at this point in the history
  • Loading branch information
likaiqiang committed Nov 18, 2023
1 parent de8f5e0 commit 096bd8e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lx-music-mobile",
"version": "1.2.0-beta.3.3",
"version": "1.2.0-beta.3.4",
"versionCode": 62,
"private": true,
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/core/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListIt


export const setMusicUrl = (musicInfo: LX.Music.MusicInfo | LX.Download.ListItem | LX.Music.MusicInfoDownloaded, isRefresh?: boolean) => {
console.log('setMusicUrl');
// addLoadTimeout()
if (!diffCurrentMusicInfo(musicInfo)) return
if (cancelDelayRetry) cancelDelayRetry()
Expand Down
10 changes: 5 additions & 5 deletions src/screens/Home/Vertical/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ const SettingPage = () => {
const DownloadPage = () => {
const [visible, setVisible] = useState(commonState.navActiveId == 'nav_download')
const [path, setPath] = useState('')
const downloadRef = useRef<DownloadTypes>(null)
const component = useMemo(() => {
return <Download path={path} />
}, [path])
return <Download ref={downloadRef} />
},[])

useEffect(() => {
const handleNavIdUpdate = (id: CommonState['navActiveId'], params?:{path:string}) => {
const handleNavIdUpdate = (id: CommonState['navActiveId']) => {
if (id == 'nav_download') {
requestAnimationFrame(() => {
void InteractionManager.runAfterInteractions(() => {
Expand All @@ -192,11 +193,10 @@ const DownloadPage = () => {
console.log('handleLaunchFilePathUpdated',path);
requestAnimationFrame(() => {
void InteractionManager.runAfterInteractions(() => {
setPath(path)
downloadRef.current?.setFilePath(path)
requestAnimationFrame(()=>{
console.log('start 000');
global.state_event.navActiveIdUpdated('nav_download')
// setPath('')
})
})
})
Expand Down
30 changes: 13 additions & 17 deletions src/screens/Home/Views/Download/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,49 +65,50 @@ function generateEmptyLocalMusicInfo(fullName: string, dir: string): LX.Music.Mu
}

export interface DownloadTypes {
playFilePath: (path:string)=>void
}
interface DownloadProps{
path: string
setFilePath: (path: string)=>void
}

export default React.forwardRef<DownloadTypes,DownloadProps>(({path},ref) => {

export default React.forwardRef<DownloadTypes,{}>((_, ref) => {
const listRef = useRef<ListType>(null)
const [list, setList] = useState<LX.Music.MusicInfoDownloaded[]>([])
const listMenuRef = useRef<ListMenuType>(null)
const confirmAlertRef = useRef<ConfirmAlertType>(null)
const [selectMusicInfo, setSelectMusicInfo] = useState<LX.Music.MusicInfoLocal>()
const playMusicInfo = usePlayMusicInfo()
const timerRef = useRef<number>()
const [path, setPath] = useState('')
const pathRef = useRef<string>(path)
pathRef.current = path
const dirRef = useRef(`${RNFetchBlob.fs.dirs.DownloadDir}/lx.music`)

console.log('download render',path)

const updateDownloadedList = async ():Promise<void> =>{
if(timerRef.current) BackgroundTimer.clearTimeout(timerRef.current)
console.log('updateDownloadedList',pathRef.current);
if(pathRef.current){
dirRef.current = pathRef.current.substring(0, pathRef.current.lastIndexOf('/'))
}
timerRef.current = BackgroundTimer.setTimeout(()=>{
scanMusicFiles(dirRef.current).then(files=>{
const updatedList = files.map((file=> generateEmptyLocalMusicInfo(file, dirRef.current)))
console.log('scanMusicFiles', updatedList);
setList(updatedList)
overwriteListMusics(LIST_IDS.DOWNLOAD, updatedList, false)
if(pathRef.current){
requestAnimationFrame(()=>{
listRef.current!.playFilePath(pathRef.current)
setPath('')
})
// BackgroundTimer.setTimeout(()=>{
//
// },300)
}
})
},300)
}

useImperativeHandle(ref,()=>{
return {
setFilePath(path:string){
setPath(path)
}
}
})
const showMenu = (musicInfo: LX.Music.MusicInfoLocal, index: number, position: Position) => {
listMenuRef.current?.show({
musicInfo,
Expand All @@ -116,11 +117,6 @@ export default React.forwardRef<DownloadTypes,DownloadProps>(({path},ref) => {
selectedList: [],
}, position)
}
useImperativeHandle(ref,()=>{
return {
playFilePath: listRef.current!.playFilePath
}
})
useEffect(() => {
updateDownloadedList().then()

Expand Down

0 comments on commit 096bd8e

Please sign in to comment.