Expo AV audio not playing on iOS/ iPhone

Viewed 1751

I have used Expo AV and developed a screen in my app to play audio files fetched from my server. It works fine on Android, but doesn't play anything on iPhone.

When I play a button to play the audio which loads and plays the file

soundObject.loadAsync({ uri: this.state.file });
soundObject.playAsync();

It returns an error:

This media format is not supported. - The AVPlayerItem instance has failed with the error code -11828 and domain "AVFoundationErrorDomain".

Here is my code that loads and plays the audio :

async loadAudio() {
soundObject = new Audio.Sound();
try {
await soundObject.loadAsync({ uri: this.state.file });
console.log("File loaded: " + this.state.file);
} catch (error) {
console.log(error);
}
}


async playAudio() {
if (!this.state.isPlayingAudio) {
try {
  
  await soundObject.playAsync();
} catch (error) {
  console.log(error);
}

  else {
soundObject.pauseAsync();
  }
  }

I have tried changing the audio format to m4a, wav, caf while recording and fetching the file but that did not help I'm running the app on iPhone 7 plus, iOS 14.2 Any suggestions/ fixes, please? Thanks in advance

3 Answers

I'm passing the uri object and a second argument {shouldPlay: true} to the loadAsync method. This plays my mp3 files from amazon server s3

await Audio.Sound.loadAsync( { uri: this.state.file }, { shouldPlay: true } )

You're calling loadAsync improperly.

The call should look like this:

await Audio.Sound.createAsync(
  { uri: this.state.file },
  { shouldPlay: true }
);

I was on Expo 44, downgrading to Expo 43 did the trick. Run expo upgrade 43.

Related