react-native-audio-recorder-player: [SOLVED] Remote audio url sent from Android won't playback on iOS device
Version of react-native-audio-recorder-player
3.0.2
, react native: 0.63.4
Platforms you faced the error (IOS or Android or both?)
iOS
Expected behavior
Play remote audio files sent from android
Actual behavior
If an Android device sends an audio message to an iOS device then the audio player won’t play that file. This lib is being used in a chat room where users exchange audio messages.
Steps to reproduce the behavior
Recording function:
import { Dirs, FileSystem } from "react-native-file-access";
const onStartRecord = async () => {
ReactNativeHapticFeedback.trigger(
hapticTriggerType as HapticFeedbackTypes,
hapticOptions
);
const path = Platform.select({
ios: "remote_audio/remote_audio_message.m4a",
android: `${Dirs.CacheDir}/remote_audio/remote_audio_message.m4a`
});
try {
const audioSet: AudioSet = {
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSamplingRateAndroid: 44100,
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.medium,
AVFormatIDKeyIOS: AVEncodingOption.aac,
AVNumberOfChannelsKeyIOS: 2,
OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS
};
const meteringEnabled = false;
stopPlayer().catch((e) =>
console.log(`error while stopping player of messages bubbles, error: ${e}`)
);
await FileSystem.mkdir(`${Dirs.CacheDir}/remote_audio`).catch((e) => console.log(e));
await audioRecorderPlayer.startRecorder(path, audioSet, meteringEnabled);
// @ts-ignore
audioRecorderPlayer.addRecordBackListener((e: RecordBackType) => {
setRecord({
recordSecs: e.currentPosition,
recordTime: audioRecorderPlayer.mmssss(Math.floor(e.currentPosition))
});
});
} catch (e) {
console.log(e);
}
};
While using version 2.7.0
it works like a charm. Upgrading to 3.0.2
won’t play the remote audio file sent by an Android device with no errors on metro or xCode console. It will just sit there and wait after tapping “play” button.
Weird thing is that the audio files being sent from iOS can be played from the remote url just fine (on iOS device). Tried to change the AudioEncoderAndroidType
and OutputFormatAndroid
into different encoders but the issue persists.
On Android everything works as it should.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 15 (11 by maintainers)
Hi, Change
AAC_ADTS
toMPEG_4
.Thanks for replying i will check those 👍
Hi, guys,
No, I don’t have any idea. AAC_ADTS is probably the only CODEC/FORMAT which is compatible both on Android and iOS.
If I understand correctly your sound follows 4 steps :
One of those 4 steps is not OK. I suggest that you :
We will have a better idea which of these 4 steps is incorrect.
I don’t quiet understand the situation. Are you saying that the audio uploaded from the
android
to your backend is not playing from theiOS
?