4

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

aheze
  • 24,434
  • 8
  • 68
  • 125
Khaja Nizamuddin
  • 167
  • 1
  • 2
  • 9

4 Answers4

2

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 } )

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 13 '21 at 22:49
2

You're calling loadAsync improperly.

The call should look like this:

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

Please add this method before playing soundd view "expo-av"

const enableAudio = async () => {
await Audio.setAudioModeAsync({
playsInSilentModeIOS: true,
staysActiveInBackground: false,
interruptionModeAndroid: INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
shouldDuckAndroid: false,

})

Manish Arora
  • 397
  • 3
  • 12
  • Not sure why this doesn't have upvotes, it fixed the issue or me on iOS. – Globe May 07 '23 at 05:07
  • 1
    `playsInSilentModeIOS` solved the issue for me as well! Some reference to these parameters or what to they do would be appreciated also. – Diplodoco Jul 10 '23 at 18:54
-3

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

Travis Hoki
  • 198
  • 1
  • 15