在react native中使用base64字符串播放音频

问题描述

我已使用 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)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...