繁体   English   中英

反应性音频发送问题

[英]react-native audio sending issue

我正在尝试发送音频文件,但我认为我没有正确选择文件。 我正在使用react-native-audio-toolkit,并且试图在它记录的地方使用rec对象,但这似乎不起作用,如何获取文件进行发送? 码:

let rec = new Recorder("filename.mp4").record();

// Stop recording after approximately 3 seconds
setTimeout(() => {
  rec.stop(err => {
    // NOTE: In a real situation, handle possible errors here
    let data = new FormData();
    data.append("recording[path_to_recording]", rec);
    data.append("recording[challenge_id]", 1);
    data.append("recording[user_id]", 1);
    console.log(data);
    axios
      .post(config.API_URL + "recordings", data, {
        headers: {
          Authorization: "Bearer " + this.props.auth.token
        }
      })
      .then(res => res.data);

记录文件的日志如下所示:

记录器{_path:“ filename.mp4”,_ options:{…},_ recorderId:0,_state:-2,_duration:-1,…} _duration:-1 _fsPath:“ / data / user / 0 / com.cobrn / files / filename.mp4“ _lastSync:-1 _options:autoDestroy:(...)get autoDestroy:ƒ()set autoDestroy:ƒ() proto :对象_path:” filename.mp4“ _position:-1 _recorderId:0 _state: -2 canPrepare:(...)canRecord:(...)fsPath:(...)isPrepared:(...)isRecording:(...)state:(...) proto :EventEmitter

弄清楚了,您需要指定类型

data.append("recording[path_to_recording]", {
      uri: "file://" + rec._fsPath,
      name: "filename.mp4",
      type: "audio/mp4"
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM