小程序上传语音505错误
发布于 5 年前 作者 ycao 8735 次浏览 来自 问答

小程序上传语音错误显示505状态 只有部分手机有这种情况,安卓6.1一下版本,

  longtap: function () {

    var that = this;

    const recorderManager = wx.getRecorderManager();

    console.log(“当前录音状态:”+this.data.lock);

    if (ly) {

      wx.showToast({

        title: ‘正在录音,再次点击结束录音’,

        icon: “none”,

        duration: 10000

      })

      setTimeout(function () {

        wx.hideToast()

      }, 1500);

      ly = false;

    } else {

      ly = true;

      wx.showToast({

        title: ‘录音结束’,

        icon: “none”,

        duration: 10000

      })

      setTimeout(function () {

        wx.hideToast()

      }, 1000);

    }

    if (this.data.lock) {

      recorderManager.stop();

      //开锁

      setTimeout(() => {

        this.setData({ lock: false });

      }, 100);

    } else {

      this.setData({ lock: true });

      //========= 调用录音接口的事件处理=============

      recorderManager.onStart(() => {

        console.log(‘recorder start’)

      })

      recorderManager.onPause(() => {

        console.log(‘recorder pause’)

      })

      recorderManager.onStop((res) => {

        console.log(‘recorder stop’, res)

        const { tempFilePath } = res;

        mymusic = res.tempFilePath;

        j = that.data.current-1;

        xid = dataarry[j];

        word = dataword[j];

        // 录音成功了点击?才会有分,否则提示加载中

        lya = false;

        wx.showLoading({

          title: ‘正在加载分数’,

        })

        var urla = app.globalData.baseUrl;

        // var urla =‘http://192.168.3.19:8080/englishService/

        // urla.replace(/\s+/g, ‘%20’)

        wx.uploadFile({

          url: urla + ‘service.action?json={“cmd”:“uploadreadBook”,“id”:"’ + xid + ‘",“uid”:"’ + uid + ‘",“isvip”:"’ + isvip + ‘",“word”:"’ + word + ‘"}’,

          filePath: mymusic,

          name: “file”,

          header: {

            ‘content-type’: ‘multipart/form-data’

          },

          formData: {

          },

          success: function (res) {

            wx.hideLoading();

            console.log(res)

            var data1 = JSON.parse(res.data);

            console.log(data1)

            if (data1.result == “0”) {

              lya=true;

              that.setData({

                score: data1.score,

                mysound:data1.mysound,

                arrywore: data1.word,

                arrwore1: data1.word,

                colortype:false

              });

              console.log(data1.mysound)

              that.audioPlay();

              // const inner = wx.createInnerAudioContext();

              // inner.src = data1.mysound;

              // inner.play();

              if (data1.score==“0”){

                  colortype:true

              }

              // 把当前录音的文件存到一个数组里面

              console.log(that.data.current)

              lydata[that.data.current - 1] = 1;

 

              if (lydata.length == that.data.hearReadList) {

                that.setData({

                  relsocre: true

                });              

              } 

            } else {

              wx.showToast({

                title: data1.resultNote,

              })

            }

            that.setData({

              src: res.tempFilePath,

              checkflag: false,

              mucsrc: true

            })

          },

          fail: function (res) {

            console.log(res)

          }

        })

   

      })

      recorderManager.onFrameRecorded((res) => {

        const { frameBuffer } = res

        console.log(‘frameBuffer.byteLength’, frameBuffer.byteLength);

      })

      const options = {

        sampleRate: 16000,

        encodeBitRate: 96000,

        numberOfChannels: 1,

        format: ‘mp3’,

      }

      recorderManager.start(options);

    }

    console.log(‘触发了 longtap’)

  },

回到顶部