zoukankan      html  css  js  c++  java
  • 微信小程序踩坑(二)——微信小程序recorderManager和innerAudioContext相关

    写在前面

    关于微信小程序的录音和语音方面,踩了很多坑,记录一下
    recorderManager相关文档
    innerAudioContext相关文档

    RecorderManager录音相关

    • 在使用RecorderManager相关方法之前,在page外先定义全局唯一的录音管理器:
    const recorderManager = wx.getRecorderManager();
    
    • 录音开始
    recorderManager.start(options);
    

    经常使用的options的参数:
    1.duration:录音时长,默认类型number,默认值60000(10分钟),单位ms;
    2.format:音频格式,默认类型aac,默认值string,可选mp3、aac、wav、PCM;

    使用recorderManager.start时会弹窗语音授权。

    • 录音停止
    recorderManager.stop();
    
    • 录音暂停
    recorderManager.pause();
    
    • 录音继续
    recorderManager.resume();
    
    • 常用监听事件相关
    // 1.监听录音开始
    recorderManager.onStart(function callback);
    // 2.监听录音停止
    recorderManager.onStop(function callback);
    // 3.监听录音暂停
    recorderManager.onPause(function callback);
    // 4.监听录音继续
    recorderManager.onResume(function callback);
    // 5.监听录音错误
    recorderManager.onError(function callback);
    

    innerAudioContext播放相关

    • 在使用RecorderManager相关方法之前,在page外先定义全局唯一的录音管理器:
    const innerAudioContext = wx.createInnerAudioContext();
    

    innerAudioContext常用的属性:

    1. src —— 音频地址
      踩坑注意:在ios系统中音频地址的左斜杠‘/’和右斜杠‘’并不通用,使用右斜杠会导致音频无法播放!!!!
    2. autoplay —— 是否自动播放 默认为false
    3. loop —— 是否循环播放 默认为false
    4. obeyMuteSwitch —— 是否遵循系统静音开关 默认为true
      踩坑注意:在ios系统中,如果obeyMuteSwitch为默认值true,那么在系统静音的时候扬声器不会播放音频,但是耳机可以!!!如果有需要,请将obeyMuteSwitch值设置为false
    • 音频播放
    innerAudioContext.play();
    
    • 音频停止
    innerAudioContext.stop();
    
    • 音频暂停
    innerAudioContext.pause()
    
    • 常用监听事件相关
    // 1.监听音频自然播放到结束
    innerAudioContext.onEnded(function callback);
    // 2.监听音频错误
    innerAudioContext.onError(function callback);
    // 3.监听音频暂停
    innerAudioContext.onPause(function callback);
    //4. 监听音频播放
    innerAudioContext.onPlay(function callback)
    
  • 相关阅读:
    LNMP
    Unable to guess the mime type as no guessers are available 2 9
    django--模型字段引用
    no python application found, check your startup logs for errors
    uWSGI+django+nginx的工作原理流程与部署历程
    进程管理supervisor的简单说明
    Django 部署(Nginx)
    MyBatis学习教程
    Spring教程
    互联网的寒冬该如何度过
  • 原文地址:https://www.cnblogs.com/lzb1234/p/12493123.html
Copyright © 2011-2022 走看看