hyochan/react-native-audio-recorder-player

Unable to hear android recorded voice on iOS and iOS recorded voice on android

taha200 opened this issue · 4 comments

I am working on the voice note feature in chat, right now I am sending the file to the backend and play the voice from URL and it works on the android phone from which I sent the voice note but unable to hear this from another iOS phone and same for the file that is being sent by the iOS and unable to hear on android, I also used the file system to first download the voice and then play and this work around is also not working

Version of react-native-audio-recorder-player

3.6.4

Version of React Native

0.71.14

Platforms you faced the error (IOS or Android or both?)

both

Expected behavior

listen on both OS despite sending from any device.

Actual behavior

Explained in description.

How did you set the path ?
Did you check if the format is supported vise versa ?

Facing same issue, is anyone looking into this issue ?

Below is the code which i am following:

Start recording:

import RNFS from 'react-native-fs';
import AudioRecorderPlayer from 'react-native-audio-recorder-player';

const audioRecorderPlayer = new AudioRecorderPlayer();

    const dirs = RNFS.DocumentDirectoryPath;
    const path = Platform.select({
      ios: 'temporary_voice.m4a',
      android: `${dirs}/temporary_voice.mp3`,
    });

    const result = await audioRecorderPlayer.startRecorder(path);
    audioRecorderPlayer.addRecordBackListener(e => {
      console.log('Recording...', e);
    });

End Recording:

       const result = await audioRecorderPlayer.stopRecorder();
      audioRecorderPlayer.removeRecordBackListener();
      setRecordedURI(result);

Recording sent to my database:

        const fileContent = await RNFS.readFile(recordedURI, 'base64');
        const fileName = `recordings/${Date.now()}.mp3`;
        let payload = {
          fileName,
          fileContent,
          chatId,
        };

Which then returns the url, android audio works only on android and ios only works on ios,

import AudioRecorderPlayer, {
AVEncoderAudioQualityIOSType,
AVEncodingOption,
AudioEncoderAndroidType,
AudioSourceAndroidType,
OutputFormatAndroidType,
} from 'react-native-audio-recorder-player'

const result = await audioRecorderPlayer.startRecorder(undefined,{
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
AVNumberOfChannelsKeyIOS: 2,
AVFormatIDKeyIOS: AVEncodingOption.aac,
OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS,
})

Just import these properties and send this in the object as a second param, then you can play the voices on cross-platform if you record with these options.
@MrFarhan