2

I keep getting this error when i try to play an audio from my local backend or an already uploaded audio from a site. No matter what file format, this is what I get and this only happens with ios

error: Possible Unhandled Promise Rejection (id: 0): Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain". Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain". error image

const player = new Audio.Sound();
player.loadAsync({ uri: url }, initialStatus).then(() => {
    player.playAsync().then((playbackStatus) => {
        if (playbackStatus.error) {
                                 
          handlePlaybackError(playbackStatus.error);
        }
    });
});

After adding more error handling, I found out the error comes from loadAsync and it only happens when I try to play an audio from my local backend server. (ex: http://127.0.0.1:8000/media/audios/2021/08/08/27/21/filename.mp4)

It would be really great if I could get help on this, thanks in advance! Update: Provided more code

2 Answers2

2

So I found out that the that warning was being generated and preventing my audio files from playing because they are stored in my local server and for some reason the expo Audio.Sound object had an issue loading them, so I had to install expo-file-system, use the FileSystem to read download the file and use the uri produced from the download. Example:

import * as FileSystem from 'expo-file-system';

    const splitUrl = url.split('/');
    const lastItem = splitUrl[splitUrl.length - 1];
    const { uri } = await FileSystem.downloadAsync(
        url,
        FileSystem.documentDirectory + lastItem
    );
    const source = { uri: uri }; //the source you provide to the loadAsync() method

1

loadAsync() returns a Promise, so you have to await it. If this is not the problem you have to provide more code, please.

Here's the documentation, so use it like this:

const sound = new Audio.Sound();
try {
  await sound.loadAsync(require('./assets/sounds/hello.mp3'));
  await sound.playAsync();
  // Your sound is playing!

  // Don't forget to unload the sound from memory
  // when you are done using the Sound object
  await sound.unloadAsync();
} catch (error) {
  // An error occurred!
}

And here's a simple snack I made, it works for me, you might want to consider error handling using try-catch: Snack example

m_wer
  • 1,038
  • 1
  • 11
  • 19