Strange: Local files fail to load, but only for previously downloaded file
See original GitHub issueHi all,
I’m using react-native-sound to play files downloaded with react-native-fetch-blob and stored in local storage. But strangely, while I’m able to immediately play the file right after it’s downloaded and stored, the file fails to load after I close the app and restart again. Here’s a screenshot of the console: Section 4 is freshly downloaded and I’m able to play it, while Section 5 was a file downloaded in the previous run of the app. As you can see, the file path structure is exactly the same. So I’m rather baffled by why this is happening!
Here’s the part of my code that handles file loading and playing:
let Playing
function setCurrentPlaySession(section) {
console.log('set play session to: ', section.section_id)
return {
type: types.PLAYING,
payload: section
}
}
export function playFile(sectionInfo) {
return (dispatch) => {
Playing = new Sound(sectionInfo.filePath,'', error => {
if(error) {
console.log(`Is section ${sectionInfo.section.section_id} loaded? ${Playing.isLoaded()}`)
console.log(`failed to load section: ${sectionInfo.section.section_id}`, sectionInfo.filePath, error)
return
}
dispatch(getPlayDuration(Playing.getDuration()))
console.log(`section ${sectionInfo.section.section_id} is playing from ${sectionInfo.filePath}`)
dispatch(setCurrentPlaySession(sectionInfo.section))
if(sectionInfo.currentProgress) {
Playing.setCurrentTime(sectionInfo.currentProgress)
}
Playing.play((success) => {
console.log('finished playing ')
})
})
}
}
Any insights on this would be much appreciated. Thanks!
This is only on IOS simulator. I’m using react-native 0.41 and react-native-sound 0.9.
Oh, and I also tried rolling back to v 0.8 of the library, as suggested by one response in a similar open issue before this one. It didn’t help. Playing audio is the most key functionality of my app. So I’m rather frustrated right now. Looking into other libraries. But I really like this one, when it works.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:15 (2 by maintainers)
Top GitHub Comments
Try replacing Sound.MAIN_BUNDLE with ‘’. Otherwise it’ll prepend your path with path to the bundle itself which you probably don’t want
I made the following change to make it work, at least on simulator for now. Not sure what’d happen on an actual phone.
When retrieving the file, instead of using the file path as returned by res.path() as in the code above, I now directly use filePath = RNFetchBlob.fs.dirs.DocumentDir + ‘/courseSections/’ + sectionInfo.section.section_id + ‘.mp3’ when retrieving the file.
But at the end of the day, this is not a react-native-sound issue. So I’m closing this thread for now. Thanks everyone for the inputs!