jibidijib
jibidijib

Reputation: 417

Playing S3 audio with Expo-AV

I'm trying to play an audio from my aws s3 bucket with the use of expo-av but it deosnt work. It's my first time using expo-av but I believe the issue lies in pointing the source url to my aws API. Below is my code. I'm quite sure I screwed up here so an explanation to the answer will be very much appreciated.

 Audio.setIsEnabledAsync(true)

    Audio.setAudioModeAsync(
      {playsInSilentModeIOS : true,
        allowsRecordingIOS : true,
        staysActiveInBackground : true,
        interruptionModeIOS : {
          interruptionModeIOS : true,
          INTERRUPTION_MODE_IOS_DO_NOT_MIX: true,
          INTERRUPTION_MODE_IOS_DUCK_OTHERS: true,
        },
        interruptionModeAndroid : {
          INTERRUPTION_MODE_ANDROID_DO_NOT_MIX: true,
          INTERRUPTION_MODE_ANDROID_DUCK_OTHERS: true,

        },
        playThroughEarpieceAndroid: true,
      }
    )

    export default class Audiol extends Component {

    state = {
        ...
      };

   componentDidMount() {
    Storage.get(this.props.a)
            .then(result =>{ console.log("Storageb");
             const Me = result;
             this.setState({Audio: Me})
             console.warn("geb")

            })
            .catch(err => console.log("S.ERROR",err))

    }

    async handleaudio() {
      const soundObject = new Audio.Sound;
        try {
          soundObject.setOnPlaybackStatusUpdate(onPlaybackStatusUpdate);
          await soundObject.loadAsync({uri: this.state.Audio}, {}, true);

          console.warn("success")
        } catch (error) {
          console.warn("error", error, this.state.Audio)
          // An error occurred!
        }      
      }

UPDATE: Just noticed that this error only occours when I use this.state.Audio if I use say the exact link given by state.Audio in the below manner it works.

await soundObject.loadAsync({uri: 'https://...amazonaws.com/...'});

But I need it to work with state.

Hope some one can help me. Thanks!

Upvotes: 2

Views: 1503

Answers (1)

morissetcl
morissetcl

Reputation: 564

Can you provide us the result of this.state.audio during your try?

Also can you try the following code inside your handleaudio function:

const myAudio = Audio.Sound.createAsync({uri: this.state.Audio}, {}, true); myAudio.playbackInstance.playAsync()

Upvotes: 1

Related Questions