javascript - 在 native react 中通过表单数据发送音频

标签 javascript android ios react-native audio

我正在尝试使用库 here 发送音频文件一切正常,录制、停止和播放音频,但是当我尝试通过 formdata 发送此音频文件时,文件中断。

这是我的代码:

formData.append("data[file_name]", {
  uri: this.state.uriAudio,
  name: Platform.OS === 'android' ? 'test.mp4' : 'test.m4a',
  type: Platform.OS === 'android' ? 'audio/mp4' : 'audio/m4a',
})

但是当文件到达时,音频文件格式发生了变化,这些是我得到的结果:

"file": {
           "url": "http://.......",
           "name": "test.m4a",
           "content_type": "audio/x-m4a",
           "upload_date": "Dec  5, 2018",
           "size": "3 MB"
       }

当我尝试播放音频时,格式已损坏。

提前致谢

最佳答案

我找到了一个解决方案,但使用了另一个库,react-native-soundreact-native-audio

在项目中导入的方式是:

import {AudioRecorder, AudioUtils} from 'react-native-audio';
import Sound from 'react-native-sound';

formData.append("data[file_name]", {
      uri: Platform.OS == 'android' ? 'file://' + this.state.uriAudio:this.state.uriAudio,
      name: 'test.aac',
      type: 'audio/aac'
    })

这个方法对我有用,希望你能帮到他们

关于javascript - 在 native react 中通过表单数据发送音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53661803/

相关文章:

javascript - 无需点击 Chrome 插件即可获取 URL

android - TextView - setCustomSelectionActionModeCallback 如何为多个 TextView 选择文本时创建 ActionMode.Callback

android - 如何裁剪 Android 中已知 URI 的图像?

android - 如何使用 Android 的 Oboe/AAudio 从多个麦克风读取数据

iphone - NSURLConnection 忽略 Keep-Alive 超时?

ios - 使用 coredata 时 Tableview 行平滑动画

javascript - Angular 2 : Toggle Boolean based on a condition

javascript - 点击表单提交后如何 "GO BACK"到上一页?

javascript - 无限滚动: Loading more data with Ajax call?

iphone - 在bannerViewActionDidFinish : Bug or Not?之后AdBannerView移动到 super View 的顶部