使用录音功能,每次进入页面,点击开始录音时候,都会提示‘***。要使用你的录音功能,请允许’;这要怎么解决呢
代码:
var time ={ //时长
      start:'',
      end:''
    };
    var voice = {
    localId: '',
    serverId: ''
    };
    if(!localStorage.rainAllowRecord || localStorage.rainAllowRecord !== 'true'){
        wx.startRecord({
            success: function(){
                wx.stopRecord();
                localStorage.rainAllowRecord = 'true';
                
            },
            cancel: function () {
              wx.stopRecord();
              alert('用户拒绝授权录音');
            }
        });
    }
  //按下开始录音
    $('#startRecord').on('touchstart', function(event){
        event.preventDefault();
        time.start = new Date().getTime();
        recordTimer = setTimeout(function(){
            wx.startRecord({
                success: function(){
                    localStorage.rainAllowRecord = 'true';
                },
                cancel: function () {
                    alert('用户拒绝授权录音');
                }
            });
        },300);
    });
    //松手结束录音
    $('#startRecord').on('touchend', function(event){
        event.preventDefault();
        time.end = new Date().getTime();       
        if((time.end - time.start) < 300){
            time.end = 0;
            time.start = 0;
            //小于300ms,不录音
            clearTimeout(recordTimer);
        }else{
            wx.stopRecord({
              success: function (res) {
                voice.localId = res.localId;
                alert(res.localId);
                //panduan(res.localId);
              },
              fail: function (res) {
                alert(JSON.stringify(res)+'123');
              }
            });
        }
    });