我在领域数据库中存储了一个mp3文件。如何在React Native中播放该文件?我试图将其转换为字符串base64,并使用react-native-sound进行播放,但似乎不起作用。
returnSoundString = () => {
let binary = '';
const bytes = new Uint8Array(soundData);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
this.sound = new Sound(`data:audio/mp3;base64,${this.returnSoundString()}`, '', (error) => {
if (error) {
console.log('failed to load the sound', error);
} else { // loaded successfully
console.log('Loaded successfully');
}
})