4

I'm trying to build a simple audio player that loads a file from our server and plays it. Currently this code works on Android but iOS doesn't work, throwing the error

AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain"

From what I've gathered, this is an issue with iOS expecting a file extension when it tries to load the audio file. We are using the exact same server route on our React web app with no problems, it's able to load the file within a simple audio html element. Android is also functioning with the React Native code below:

const loadNewPlaybackInstance = async playing => {
  const source = { uri: url } // defined as `${api}/api/v1/voicemail?s3_email_id=${s3_email_id}`
  // This returns a voicemail.wav file 

  const initialStatus = {
    shouldPlay: playing,
    rate: 1.0,
    volume: volume,
    isMuted: false,
  }

  try {
    const { sound } = await Audio.Sound.createAsync(
      source,
      initialStatus,
      onPlaybackStatusUpdate,
    )
    setPlaybackInstance(sound)

    updateScreenForLoading(false)
  } catch (error) {
    console.error(error.message)
  }
}

I've found another SO question, but there isn't a real answer.

There is also an open issue on Github which seems to be forgotten that I've also tried to revive.

Does anyone have any insight into how to resolve this issue? Let me know if there is more detail/context needed to help.

Loquen
  • 41
  • 1
  • 5

2 Answers2

1

I was having the same problem after changing setAudioModeAsync Audio started playing on the speaker.

the configuration would be this:

await Audio.requestPermissionsAsync();
await Audio.setAudioModeAsync({
  staysActiveInBackground: true,
  interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
  shouldDuckAndroid: false,
  playThroughEarpieceAndroid: false,
  allowsRecordingIOS: false,
  interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
  playsInSilentModeIOS: true,
});
0

Please add this method before playing soundd view "expo-av" and check Platform.OS==="ios" before calling the method

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

})

Manish Arora
  • 397
  • 3
  • 12