react-native-audio-recorder-player
react-native-audio-recorder-player copied to clipboard
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?
I use to convert my audio tp mp3 files with ffmpeg and they all played well in both iOS and android. It looks awkward to me.
Also for the 3.0.10 compile issue, please follow the readme and try the example project and come back.
I managed to create the swift bridging header. However, I still can't compile the project. I'm getting this error:
The following build commands failed:
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
CompileSwift normal x86_64 [...]/app/node_modules/react-native-audio-recorder-player/ios/RNAudioRecorderPlayer.swift
Could it be related to my XCode version? I have 12.5
It works now, I had to change the Deployment Target for the plugin from 9.0 to 10.0. However, mp3 files still don't work. M4A files work perfectly fine, but for MP3 files (recorded by this same plugin, from an Android device) the playback listener runs only twice. The first run has currentPosition 0, and the second one has different positions greater than 0, but it doesn't run again. The playback listener also has the correct duration, so the audio file exists and the plugin is reading it, but it can't be played for some reason. Both M4A and MP3 can be played without problems on Android, this only happens in iOS. Any ideas?
I tried to play the same mp3 file directly from the server, sending the url to startPlayer, and it worked. But if I download the MP3 file and then try to play it locally, it doesn't work.
@MarioUnlam I think we need that mp3 file to investigate
https://www.mediafire.com/file/g4hdz02mb9rkq7f/fa418bdf-469c-431d-86f2-58dc6c4ee102.mp3/file
This is one of the files we use. It's just an audio recording, made in Android, with react-native-audio-recorder-player. Like I said above, it works fine on Android. On iOS, it only works if I try to play it directly from a link, but not if I download the file (with react-native-fs) and then try to play it locally. I also tried to play it from a MAC (loading the file directly from the emulator folder) and it works fine, so the file doesn't seem to be corrupted.
I think im having a similar issue. I downloaded a file that I made with react-native-audio-recorder-player, and it wont play in the chrome browser, however it works fine in VLC.
EDIT:
Adding the following audio set fixed my issue:
const audioSet: AudioSet = {
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
AVNumberOfChannelsKeyIOS: 2,
AVFormatIDKeyIOS: AVEncodingOption.aac,
};
I use the same AudioSet. Maybe using a different encoder for Android could solve the problem? (since all the MP3 I can't play on iOS were recorded on Android)
I am facing the same issue. I am not able play audio clip in ios that is recorded in android but in IOS it works fine.Please help me to fix this. I am struck from a longer time.
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');
@naydenow Thanks, It worked for me. (iOS)
@naydenow Thanks for the help! If you think this should be applied in sourcecode please open a PR 🙏
Happy New Year 🎉
I'm also getting "Command CompileSwiftSources failed with a nonzero exit code" on target RNAudioRecorderPlayer, what can I do?
so, is it possible play mp3 data from url ?
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.
const AudioSet = {
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS, // <-- this line
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
AVNumberOfChannelsKeyIOS: 2,
AVFormatIDKeyIOS: AVEncodingOption.aac,
}