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

Demo not working using a url...

Open PeterEmanuel opened this issue 9 years ago • 5 comments

I have built the demo and it works. If I replace the line

const s = new Sound('advertising.mp3', Sound.MAIN_BUNDLE, (e) => {

with

const s = new Sound('https://api.example.com/tracks/test.mp3', '', (e) => {

I get the following error in the Android monitor:

Attempt to call getDuration without a valid mediaplayer

No error message from the demo code.

Should it be possible to use this module with urls anyway? (I read about the underscore things, but I am not using uppercase letters).

The above url is of course not my real one ;-)

Cheers

PeterEmanuel avatar May 16 '17 15:05 PeterEmanuel

What's the real URL you're using?

bighitbiker3 avatar May 17 '17 01:05 bighitbiker3

This looks like a duplicate of #175. Currently it doesn't seem like it's able to play sounds from the network on android. I'm also having this issue and would love to know if it's going to be fixed or if anyone has a workaround.

gshotwell avatar May 19 '17 16:05 gshotwell

you can use react-native-fetch-blob to download file audio with url and use react-native-sound to play. setTimeout(() => { RNFetchBlob .config({

                                                fileCache: true,
                                            })
                                            .fetch('GET', 'url audio', {
                                            })
                                            .then((res) => {
                                                var sound = new Sound(res.path(), '', (error) => {
                                                    if (error) {
                                                    }
                                                });
                                                setTimeout(() => {
                                                    sound.play((success) => {
                                                        if (success) {
                                                        } else {
                                                        }
                                                    });
                                                }, 100);
                                            })
                                    }, 100);

katori216 avatar May 24 '17 01:05 katori216

I was having an issue playing larger sound files from the network (small files were fine) but using @katori216's suggestion of RNFetchBlob to download the file first works.

jketcham avatar Sep 27 '17 21:09 jketcham

@jketcham I like this, but it seems a bit extreme for a demo. What if we add the example into documentation on the WIKI or have another example project.

trepidity avatar Oct 02 '17 23:10 trepidity