Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native playing audio from s3 URL using react-native-sound

I'm new to react-native and trying to create an audio playing app.

I used react-native-sound to achieve the same. In the documentation, it specifies that I can play the file from a network. But I could not find any docs for the same.

Right now I'm uploading audio files from my ROR backend and adding the file to a local folder inside react. I'm changing that to aws s3.

And the audio file is started like -

var whoosh = new Sound(this.state.soundFile, Sound.MAIN_BUNDLE, (error) => {

where this.state.soundFile is a local file name (string) inside the specified folder.

Is this possible?

like image 275
Sooraj Avatar asked Sep 03 '26 08:09

Sooraj


1 Answers

You can play remote sounds with react-native-sound by specifying a url and not setting the bundle:

import React, { Component } from 'react'
import { Button } from 'react-native'
import Sound from 'react-native-sound'

class RemoteSound extends Component {
  playTrack = () => {
    const track = new Sound('https://www.soundjay.com/button/button-1.mp3', null, (e) => {
      if (e) {
        console.log('error loading track:', e)
      } else {
        track.play()
      }
    })
  }

  render() {
    return <Button title="play me" onPress={this.playTrack} />
  }
}

export default RemoteSound
like image 60
Isilher Avatar answered Sep 05 '26 16:09

Isilher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!