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

Accessing android file from external storage based on content:// uri protocol #126

Open
Malthehave opened this issue Jun 15, 2021 · 0 comments

Comments

@Malthehave
Copy link

Hi!

I'm using react-native-document-picker version 5.0.4, to get local files on the users device.

On Android, after choosing an audio file, it returns me an object like this:

{
  "fileCopyUri": "content://com.android.providers.media.documents/document/audio%3A31", 
  "name": "file_example_MP3_700KB.mp3", 
  "size": 764176, 
  "type": "audio/mpeg", 
  "uri": "content://com.android.providers.media.documents/document/audio%3A31"
}

Now my question is how I would play this audio file, stored on the users device, via the two paths being given.
I tried calling SoundPlayer.playSoundFile(content://com.android.providers.media.documents/document/audio%3A31, 'mp3'), but it throws this error:

image

It seems that react-native-sound-player can't read the file based on the content:// protocol.
I'm using react-native-sound-player version 0.10.9.

Code to reproduce:

import DocumentPicker from 'react-native-document-picker';
import SoundPlayer from 'react-native-sound-player'

const accessFile = async () => {
    try {
        const audioRes = await DocumentPicker.pick({
            type: [DocumentPicker.types.audio],
        });

        SoundPlayer.playSoundFile(audioRes.uri, 'mp3')        
    } catch (err) {
        if (DocumentPicker.isCancel(err)) {
            // User cancelled the picker, exit any dialogs or menus and move on
        } else {
            throw err;
        }
    }

}

I hope someone can point me in the right direction, as this has been troubling me for some time now :-)

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

1 participant