问题描述
我已使用 react-native-fs 在 base64 字符串中编码音频。现在,我想解码 base64 字符串回到音频格式,并以 react-native 播放。
import RNFS from 'react-native-fs';
const [audioBase64,setAudioBase64]=React.useState(null)
RNFS.readFile(audioPath,"base64").then((res)=>setAudioBase64(res))
现在,我的base64字符串已保存在audioPath中。
顺便说一下,我正在使用 react-native-sound ,但找不到使用base64数据的任何格式来播放React-native-sound。
如果有人遇到过这种情况并解决了问题,请告诉我。
解决方法
我有些想做类似的事情, 我想首先我们需要写字符串 base 64 然后播放它 如下图:
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)