react-native-audio-recorder-player: Can't play local mp3 in iOS
Version of react-native-audio-recorder-player
2.5.3
Version of React Native
0.63.2
Platforms you faced the error (IOS or Android or both?)
iOS
Expected behavior
The MP3 file plays in an iOS device
Actual behavior
No audio plays. Playback listener runs but current_position is always 0
Steps to reproduce the behabior
- Store an mp3 file in the iOS device Documents folder
- run this with the path to the audio file:
const audioRecorderPlayer = new AudioRecorderPlayer();
let msg = await audioRecorderPlayer.startPlayer(path);
More info
The audio recorder works fine in iOS (m4a file). If I then download this audio in an Android device, it can be played normally. However, if I record audio in an Android device (mp3 file) and then try to play it in iOS, it doesn’t work. startPlayer() returns the path to the file, and the playback listener starts running. However, every playback call, the current_position is always 0, and no sound is played.
I know the version I’m using is old, but updating it didn’t help. I tried updating it to 2.7.0, and then Android also stopped working (the playback listener never runs). Then I tried to update to 3.0.10, but now I can’t even compile. I know I have to do some post-install setup, but I’m not familiar with MACs, and after fiddling a bit with XCode, I couldn’t generate the Swift Bridging Header, so I ended up rolling back to 2.5.3.
Is this plugin supposed to allow playing MP3 files in iOS?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15 (5 by maintainers)
I was facing a similar issue. I recorded audio on ios in .m4a format and was able to play it normally on android, but when I recorded audio on android in .mp3 format I couldn’t play it on ios. I added
OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS
in my “AudioSet” and it worked for me.Your can try simple fix, in RNAudioRecorderPlayer.swift change
audioPlayerAsset = AVURLAsset(url: URL(string: path)!, options:[“AVURLAssetHTTPHeaderFieldsKey”: httpHeaders])
to
audioPlayerAsset = AVURLAsset(url: audioFileURL!, options:[“AVURLAssetHTTPHeaderFieldsKey”: httpHeaders])
save audio in RNFS.CachesDirectoryPath, for example
RNFS.CachesDirectoryPath + ‘somepath/some.mp3’ play audio without absolute path, example: audioRecorderPlayer.startPlayer(‘somepath/some.mp3’);