1

I have encoded audio in base64 string using react-native-fs. Now I want to decode base64 string back to audio format and play in react-native.

import RNFS from 'react-native-fs';

const [audioBase64,setAudioBase64]=React.useState(null)

RNFS.readFile(audioPath,"base64").then((res)=>setAudioBase64(res))

Now my base64 string is saved in audioPath.

By the way for playing sound, I am using react-native-sound and I couldn't find any format to play sound in react-native-sound using base64 data.

If anyone has experienced this and resolve the issue then kindly do let me know.

Sayyam abbasi
  • 109
  • 1
  • 8

1 Answers1

0

i some how want to do something similar, i think first we need to write string base 64 and after that play it like below:

const path = '${RNFS.DocumentDirectoryPath}/${attachment}.aac';
RNFS.writeFile(path, yourBase64String, 'base64').then(() => playSound())
const playSound = () => {
const sound = new Sound(path, '', () => callback(sound))
}
const callback = () => sound.play(successCallback)