English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
小程序中提供了两种录音的API
旧版录音功能
首先启动录音,然后停止录音即可拉到音频的临时地址
启动录音:
var that = this; wx.startRecord({ success: function (res) { // 调用了停止录音接口就会触发这个函数,res.tempFilePath为录音文件临时路径 var tempFilePath = res.tempFilePath that.setData({ src: tempFilePath ) }, fail: function (res) { //录音失败的处理函数 } )
停止录音:
wx.stopRecord()
播放录音:
wx.playVoice({ filePath: src // src可以是录音文件临时路径 )
新版录音
获取全局唯一的录音管理器,然后录音都依赖他,而播放录音则需要内部 audio 上下文 innerAudioContext 对象。
获取全局唯一的录音管理器:
var that = this; this.recorderManager = wx.getRecorderManager(); this.recorderManager.onError(function(){ // Gestione del callback di errore della registrazione ); this.recorderManager.onStop(function(res){ // Dopo aver fermato la registrazione, metti l'audio registrato in res.tempFilePath that.setData({ src: res.tempFilePath ) console.log(res.tempFilePath ) );
Inizio della registrazione:
this.recorderManager.start({ format: 'mp3' // Se registrare un audio di tipo acc, cambiare in aac );
Fine della registrazione:
this.recorderManager.stop();
Riproduzione dell'audio:
this.innerAudioContext = wx.createInnerAudioContext(); this.innerAudioContext.onError((res) => { // Callback di errore di riproduzione dell'audio ) this.innerAudioContext.src = this.data.src; // Può essere il percorso temporaneo della registrazione this.innerAudioContext.play()
Indirizzo DEMO
github: https://github.com/yubang/appletRecordDemo
Sommario
Ciò che è stato introdotto dall'autore è la funzione di registrazione e riproduzione di WeChat Mini Program, spero che sia utile a tutti. Se avete qualsiasi domanda, lasciate un messaggio, l'autore risponderà tempestivamente. In questo senso, ringrazio anche tutti i sostenitori del sito di tutorial di urla!