Home Web Front-end JS Tutorial How to implement recording and playback functions in WeChat mini program

How to implement recording and playback functions in WeChat mini program

Jun 15, 2018 pm 04:21 PM
recording WeChat applet

This article mainly introduces the WeChat mini program recording and playback recording functions. The mini program provides two recording APIs, the old version recording function and the new version recording function. Friends who need it can refer to it

Two recording APIs are provided in the mini program

Old version recording function

First start recording, then stop recording to pull the audio Temporary address

Start recording:

var that = this;
  wx.startRecord({
   success: function (res) {
    // 调用了停止录音接口就会触发这个函数,res.tempFilePath为录音文件临时路径
    var tempFilePath = res.tempFilePath
    that.setData({
     src: tempFilePath
    })
   },
   fail: function (res) {
    //录音失败的处理函数
   }
  })
Copy after login

Stop recording:

wx.stopRecord()
Copy after login

Play recording:

wx.playVoice({
 filePath: src // src可以是录音文件临时路径
})
Copy after login

New version of recording

Get the globally unique recording manager, and then the recording depends on it, and playing the recording requires the internal audio context innerAudioContext object.

Get the globally unique recording manager:

var that = this;
  this.recorderManager = wx.getRecorderManager();
  this.recorderManager.onError(function(){
   // 录音失败的回调处理
  });
  this.recorderManager.onStop(function(res){
   // 停止录音之后,把录取到的音频放在res.tempFilePath
   that.setData({
    src: res.tempFilePath 
   })
   console.log(res.tempFilePath )
  });
Copy after login

Start recording:

this.recorderManager.start({
   format: 'mp3' // 如果录制acc类型音频则改成aac
});
Copy after login

End recording:

this.recorderManager.stop()
Copy after login

Play audio:

this.innerAudioContext = wx.createInnerAudioContext();
  this.innerAudioContext.onError((res) => {
   // 播放音频失败的回调
  })
  this.innerAudioContext.src = this.data.src; // 这里可以是录音的临时路径
  this.innerAudioContext.play()
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to implement offset and uniform animation in JS

How to implement table merge cells in Bootstrap

How to get the first value in the select drop-down box in JavaScript

How to get and display the password in real time in AngularJS

The above is the detailed content of How to implement recording and playback functions in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Xianyu WeChat mini program officially launched Xianyu WeChat mini program officially launched Feb 10, 2024 pm 10:39 PM

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

How to record calls on iPhone How to record incoming calls on iPhone How to record calls on iPhone How to record incoming calls on iPhone Feb 22, 2024 pm 05:52 PM

After making a call, long press to record the screen in the control center and turn on the microphone to record. Applicable model of the tutorial: iPhone13 System: IOS15.3 Analysis 1 First find and click the phone function on the mobile phone desktop. 2 Then dial a number first, then swipe down the screen to bring up the control center. 3 Then long press the screen recording icon in the control center. 4. Then click on the pop-up page to turn on the microphone. 5 Next, after the microphone is turned on, click the Start Recording option. 6. When you see the recording time starting, you can return to the call interface. 7. After the call ends, enter the control center again and click the recording button to stop recording. 8The final phone call recording will be saved in your photo album in the form of screen recording. Supplement: Why iPhone doesn’t have call recording function 1 is crucial

Simple steps to record on vivo phone Simple steps to record on vivo phone Mar 26, 2024 pm 09:11 PM

1. First find and click [Recorder] on the desktop of the vivo phone. 2. Click the red recording button in the lower left corner to start recording. 3. After the recording is completed, click the button in the lower right corner to end the recording and save it.

WeChat applet implements image upload function WeChat applet implements image upload function Nov 21, 2023 am 09:08 AM

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

How to set up automatic recording of calls with a specified number on Honor v30pro How to set up automatic recording of calls with a specified number on Honor v30pro Mar 23, 2024 am 09:16 AM

1. Click to open the dialing interface. 2. Click the three dots on the upper right and click Settings in the pop-up options. 3. Click to automatically record the call. 4. Turn on the automatic call recording function, click on the automatic recording object, and click on the specified number in the pop-up option. 5. Just set the specified number.

Implement the drop-down menu effect in WeChat applet Implement the drop-down menu effect in WeChat applet Nov 21, 2023 pm 03:03 PM

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

Use WeChat applet to achieve carousel switching effect Use WeChat applet to achieve carousel switching effect Nov 21, 2023 pm 05:59 PM

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the <swiper> tag to achieve the switching effect of the carousel. In this component, you can pass b

Implement image filter effects in WeChat mini programs Implement image filter effects in WeChat mini programs Nov 21, 2023 pm 06:22 PM

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

See all articles