Reputation: 101
I am building an audio player for my react native expo project. I am using expo-av to play the sound that I am pulling from my AWS s3 bucket. I am using expo SDK 44. Everything works fine on Android, but I am receiving an error on iOS:
[Unhandled promise rejection: Error: This media format is not supported. - The AVPlayerItem instance has failed with the error code -11828 and domain "AVFoundationErrorDomain".]
-I have tried this with both .mp3 and .m4a files
-everything works on android
-local files work on iOS (require('./myaudiotrack.mp3') but not from my bucket
-this seems to be a problem with the URL that is being returned from the s3bucket and it is working with a URL with an audio file extension.
async function PlayPause() {
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,
});
const { sound } = await Audio.Sound.createAsync(
{uri: AudioUri}, <------ this works on android, not ios
//require('../assets/zelda.mp3'), <--this works
{
shouldPlay: true,
rate: 1.0,
shouldCorrectPitch: false,
volume: 1.0,
isMuted: false,
isLooping: false,
},
);
setSound(sound);
await sound.playAsync();
}
Upvotes: 1
Views: 2520
Reputation: 101
I was able to fix the problem by declaring a file type using contentType: "audio/mp3"
during the bucket upload.
Upvotes: 1