Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Development of recording and playback by WeChat Mini Programs

Shulou Source: shulou.com Published: 2022-06-01 05:45:04 11月15日 Update

This article mainly introduces how WeChat Mini Programs realizes the development of recording and playback recording, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

With regard to the development of WeChat Mini Programs recording and playback recording, Mini Program provides two kinds of recording API.

Old recording function

First start the recording, then stop the recording to pull to the temporary address of the audio

Start recording:

Var that = this

Wx.startRecord ({

Success: function (res) {

/ / this function is triggered when the API to stop recording is called. Res.tempFilePath is the temporary path to the recording file.

Var tempFilePath = res.tempFilePath

That.setData ({

Src: tempFilePath

})

}

Fail: function (res) {

/ / handling function of recording failure

}

})

Stop recording:

Wx.stopRecord ()

Play the recording:

Wx.playVoice ({

FilePath: src / / src can be the temporary path to the recording file

})

New version of recording

Get a globally unique recording manager, and then the recording depends on him, while playing the recording requires an internal audio context innerAudioContext object.

Get a globally unique recording manager:

Var that = this

This.recorderManager = wx.getRecorderManager ()

This.recorderManager.onError (function () {

/ / callback processing of recording failure

})

This.recorderManager.onStop (function (res) {

/ / after the recording is stopped, put the recorded audio on res.tempFilePath

That.setData ({

Src: res.tempFilePath

})

Console.log (res.tempFilePath)

})

Start recording:

This.recorderManager.start ({

Format: 'mp3' / / change it to aac if recording acc type audio

})

End the recording:

This.recorderManager.stop ()

Play audio:

This.innerAudioContext = wx.createInnerAudioContext ()

This.innerAudioContext.onError ((res) = > {

/ / callback of failed audio playback

})

This.innerAudioContext.src = this.data.src; / / this can be the temporary path for recording

This.innerAudioContext.play ()

Thank you for reading this article carefully. I hope the article "how to realize the Development of recording and playback by WeChat Mini Programs" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Audio program article development path global function file processing management up and down context value interest function pull at the same time address object interface Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Apple Redmi vpn