zmxv / react-native-sound-demo

react-native-sound demo project for iOS and Android
MIT License
99 stars 103 forks source link

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

Open smithaitufe opened 6 years ago

smithaitufe commented 6 years ago

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

taheroo commented 3 years ago

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