Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't play from locally downloaded file #10

Closed
ishabo opened this issue Aug 30, 2018 · 4 comments
Closed

Can't play from locally downloaded file #10

ishabo opened this issue Aug 30, 2018 · 4 comments

Comments

@ishabo
Copy link

ishabo commented Aug 30, 2018

Hi,

I have a file downloaded this mp3: https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3 using react-native-fs into MAIN_BUNDLE on an IOS emulator. I can verify the file is there and I can play it with any audio player on my Mac /Library/Developer/CoreSimulator/Devices/594B5EDF-5E73-4040-9236-2DA23A1BAC86/data/Containers/Data/Application/A60A1E1B-EBD9-4A59-9B90-4A3148D68D7D/Documents/mpthreetest.mp3

Yet, I get this error when I run:

SoundPlayer.playSoundFile(filename, 'mp3');

image

Looking at RNSoundPlayer.m I can see that the default location is mainBundle. I tried with many files mp4, ogg but the same is happening.

When I play the URL directly with

SoundPlayer.playUrl(url)

it plays without a problem, but I need to download files first before playing it to make sure the file is available offline.

Any help would be appreciated!

@johnsonsu
Copy link
Owner

Hi, sorry about the late reply, did you manage to solve this problem? I can take a look into it if needed.

@nu5rim3
Copy link

nu5rim3 commented Sep 21, 2018

how to play downloaded sound files. am looking for a solution for the same problem.

@istvan-szilagyi
Copy link

istvan-szilagyi commented Dec 21, 2018

Well it seems you're a bit confused with the directories :)

  1. Main Bundle: this directory is read-only, so you CAN'T download files here within the application, you can see only files that you have builded into the bundle.
  2. Documents directory: this directory has read-write permissions. As I can see in your path, you have downloaded the file into this directory. The command SoundPlayer.playSoundFile can play only files from the bundle, and not Documents directory. This is the code in the Xcode project:
    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:name ofType:type];

Actually I could make it run from documents, but you will have to edit the Xcode project of this module:

  1. Open the Xcode project
  2. Open RNSoundPlayer.m
  3. Find function: RCT_EXPORT_METHOD(playUrl:(NSString *)url)
  4. After line: NSURL *soundURL = [NSURL URLWithString:url]; add the following:
if (soundURL == nil) {
   soundURL = [NSURL fileURLWithPath:url]; 
}
if (soundURL == nil) {
   return;
}

Now just call (from the React project):
SoundPlayer.playUrl('/Library/Developer/CoreSimulator/...<your path to the file>');

Cheers!

@johnsonsu
Copy link
Owner

This should be resolved by #37, thanks to @assertchris.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants