收藏
回答

为什么RecorderManager.onStop方法在平板小程序上面不生效?

RecorderManager.onStop在手机上面小程序是正常的,但是在平板 ipad上面无法结束录音。

这个方法,点击打印有这个方法:


但是代码里面就是进不去

<template>
  <view class="content">
    <view>
      <button @tap="startRecord">开始录音</button>
      <button @tap="endRecord">停止录音</button>
      <button @tap="playVoice">播放录音</button>
    </view>
  </view>
</template>


<script>
const recorderManager = uni.getRecorderManager();
const innerAudioContext = uni.createInnerAudioContext();


innerAudioContext.autoplay = true;


export default {
  components: {
   
  },
  data() {
    return {
      voicePath: ''
    };
  },
  onLoad(options) {
    let self = this;
    recorderManager.onStop(function (res) {
      console.log('进来onStop');
      console.log('recorder stop' + JSON.stringify(res));
      self.voicePath = res.tempFilePath;
    });
  },
  onShow() {
  },
  /**
 * 生命周期函数--监听页面初次渲染完成
 */
  onReady() {


  },
  methods: {
    startRecord() {
      console.log('开始录音');


      recorderManager.start();
    },
    endRecord() {
      console.log('录音结束');
      recorderManager.stop();
    },
    playVoice() {
      console.log('播放录音', this.voicePath);


      if (this.voicePath) {
        innerAudioContext.src = this.voicePath;
        innerAudioContext.play();
      }
    }
  },
};
</script>


<style lang="scss" scoped>
</style>


最后一次编辑于  2023-05-12
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容