How can I fix AVPlayerItem instance has failed with the error code -11828 and domain "AVFoundationErrorDomain"?

156 Views Asked by At

The expo-av createAsync function is working fine on my Android device, but not on iOS. I have a base64 string that holds the audio I want played. My function looks like this:

async function playAudio(dataString: string) {
        try {
            setIsPlaying(true);
            const { sound } = await Audio.Sound.createAsync(
                { uri: `data:audio/mp3;base64,${dataString}` },
                { shouldPlay: true },
                onPlaybackStatusUpdate
            );
            await sound.setRateAsync(.85, true);
            setAIResponse(sound);
        }
        catch (e) {
            console.error(e);
            setIsPlaying(false);
        }
    }

The createAsync function call returns the following error:

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

I have tried implementing solutions from this post: Expo AV audio not playing on iOS/ iPhone such as adding the following call before I try to play back audio:

await Audio.setAudioModeAsync({
playsInSilentModeIOS: true,
staysActiveInBackground: false,
interruptionModeAndroid: INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
shouldDuckAndroid: false,
});

However, none of the solutions have proven successful for me. I am also working in development mode, so I haven't tried this out in production yet.

0

There are 0 best solutions below