Paul
Paul

Reputation: 4486

React native Play an mp3 sound from http without using native components

Is there any way to reproduce a sound that is on http without using native Android/IOS components?

I found this module react-native-sound, but it uses native parts and I wanted to know if there is a way to avoid being able to use them.

Upvotes: 1

Views: 1845

Answers (2)

Kazi Hasan Ali
Kazi Hasan Ali

Reputation: 306

if you are using expo you can do something like that

const soundObject = new Expo.Audio.Sound();

playSound = async () => {
    await soundObject.loadAsync({uri:'the uri of your audio'});
    soundObject.playAsync();
}

now it should start playing your mp3 , for further details find expo documentation here https://docs.expo.io/versions/latest/sdk/audio

Upvotes: 1

Andrew
Andrew

Reputation: 28539

If you are using expo then it has support for audio, you can see in the documentation here: https://docs.expo.io/versions/v32.0.0/sdk/audio

However if you are not using expo, and made your app with react-native init then you will need to use a dependency that has native modules or write your own native module as processing audio on the javascript thread will block your app and make it unusable.

Upvotes: 1

Related Questions