question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange: Local files fail to load, but only for previously downloaded file

See original GitHub issue

Hi 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: screenshot 2017-02-28 19 39 10 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:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
benviumcommented, Mar 3, 2017

Try replacing Sound.MAIN_BUNDLE with ‘’. Otherwise it’ll prepend your path with path to the bundle itself which you probably don’t want

0reactions
natashachecommented, Mar 3, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local file appears but won't download - The Spotify Community
I'm trying to sync local files to my iPhone but for some reason certain songs won't sync, absolutely frustrating. I do see the...
Read more >
file is damaged and can't be opened. You … - Apple Community
All the files that I download from the internet return the error "*****" is damaged and can't be opened. You should move it...
Read more >
Chrome: Not allowed to load local resource - Stack Overflow
Just open the terminal and go to the folder where chrome.exe is stored and write the following command. chrome.exe --allow-file-access-from-files. Read this for ......
Read more >
Problems may occur when you try to transfer files to or from a ...
When you try to transfer files, the file transfer fails. You may receive an error message about a delayed write failure. The error...
Read more >
Fix file download errors - Google Chrome Help
This error means that there's not enough space on your computer to download the file. To fix the error: Delete some files from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found