如何在React Native中播放存储在领域数据库中的音频?

时间:2019-09-04 16:07:25

标签: react-native audio realm react-native-sound

我在领域数据库中存储了一个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');
        }
    })

0 个答案:

没有答案