帖子
帖子
用户
博客
课程
显示全部楼层
10
帖子
0
勋章
73
Y币

[插件开发] 电话录音功能

[复制链接]
发表于 2021-11-18 14:46:41
本帖最后由 神乐k 于 2021-11-18 14:48 编辑

需求: 拨打电话开启录音功能,挂断后停止录音,我用的官方模块,测试很多遍了,不接通之前还可以录制到声,电话一接通后 就录制空的声音。
实在是不知道哪里错了。求社区大神了

//拨打电话
function isCall() {
  let mobile_v = app.$data.mobile_v;
  api.confirm(
    {
      // title: '拨打电话',
      msg: "   是否给该用户拨打电话?",
      buttons: ["确定", "取消"],
    },
    function (ret, err) {
      var index = ret.buttonIndex;
      if (index == 1) {
        api.toLauncher();  //后台运行
        api.call({
          type: "tel_prompt",
          number: mobile_v,
        });
        luyin()
        // var myListeningInfo = api.require("myListeningInfo");
        // myListeningInfo.start(function (ret, err) {
        //   if (ret.status > 0) {
        //     console.log("监听通话中...");

        //     if (ret.telType == 1) {
        //       console.log("等待接电话号码:" + ret.phoneNumber);
        //     }
        //      else if (ret.telType == 2) {
        //        console.log("电话挂断号码:" + ret.phoneNumber);
        //        endLuyin()
        //     }
        //      else if (ret.telType == 3) {
        //        console.log("通话中号码:" + ret.phoneNumber);
        //        luyin();
        //     }
        //   }else{
        //     console.log(11111);
        //   }
        // });
      } else {
        console.log("用户点击取消");
      }
    }
  );
}

// 开始录音
function luyin() {
  console.log("开始录音");
  api.startRecord({
  path: 'fs://a.amr',
  format:'aac'
}, function(ret, err){
  console.log(JSON.stringify(ret));
if(ret){
     api.toast({
             msg:'正在录音',
             location: "bottom",
     })
  console.log(JSON.stringify(ret));
}
});
}
//录音结束
function endLuyin() {
  console.log("录音已结束");
  api.stopRecord(function (ret, err) {
    console.log(JSON.stringify(ret));
    if (ret) {
      var path = ret.path;
      var duration = ret.duration;
      api.alert({
        msg: "文件路径--" + path + ";录音时长:" + duration + "s",
      });
    }
  });
}
//播放录音
function playLuyin() {
  api.confirm(
    {
      msg: "   是否播放?",
      buttons: ["确定", "取消"],
    },
    function (ret, err) {
      var index = ret.buttonIndex;
      if (index == 1) {
        api.startPlay(
          {
            path: "fs://a.amr",
          },
          function () {
            api.alert({
              msg: "播放完毕",
            });
          }
        );
        console.log(JSON.stringify(ret));
      } else {
        console.log("用户未播放");
      }
    }
  );
}

您需要登录后才可以回帖 登录

本版积分规则