react-native-sound-demo icon indicating copy to clipboard operation
react-native-sound-demo copied to clipboard

How to play sound that is not remote or bundled in assets

Open smithaitufe opened this issue 7 years ago • 1 comments

Thanks so much for the React Native Sound package.

I have tested the package with remote files and required ones using require module. But my problem is playing a file that is not in the two categories above.

For example, I use react-native-document-picker which allows the user to select a file from the phone storage. I want to play that sound but I am not able.

Please what is the suggested way of dealing with sort like that?

        let callback = (error, sound) => {
            if (error) {
                console.log('failed to load the sound', error);
                return;
            }
            sound.play(() => {               
                sound.release();
            });
        }
        let soundFile = this.props.uri
        soundFile = require("../assets/audio/advertising.mp3") //working fine
        var sound = new Sound(soundFile, error => callback(error, sound));
        soundFile = "https://raw.githubusercontent.com/zmxv/react-native-sound-demo/master/frog.wav" //this working.
        var sound = new Sound(soundFile, "", error => callback(error, sound));
        soundFile=this.props.uri //not working. The uri is the location of the file selected by the user. Sample uri looks like "file://content://com.android.externalstorage.documents/document/300C-0FED%3AMusics%2FJWLibrary%2Fiacu_E_03.mp3"
        var sound = new Sound(soundFile, "", error => callback(error, sound));

Thank you for your prompt response

smithaitufe avatar May 19 '18 10:05 smithaitufe

Hey @smithaitufe Did you find any solution ? I am stuck at this now

taheroo avatar Sep 08 '21 21:09 taheroo