Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report