Home Web Front-end JS Tutorial How to call recording and play recording in WeChat applet

How to call recording and play recording in WeChat applet

Apr 13, 2018 pm 03:46 PM
Applets recording play

This time I will show you how to call recording and playback of recording by WeChat applet. What are the precautions for WeChat applet to call recording and playback of recording. The following is a practical case, let’s take a look.

The mini program provides two recording APIs

Old version recording function

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

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 recording

Get the globally unique recording manager, and then all recordings depend 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

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:



The above is the detailed content of How to call recording and play recording in WeChat applet. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to stream video or mirror your iPhone or iPad screen using AirPlay How to stream video or mirror your iPhone or iPad screen using AirPlay Jul 14, 2023 pm 07:53 PM

This quick guide will show you how to use AirPlay, Apple's innovative wireless streaming feature to easily share and display content. Allows you to use Wi-Fi to connect your iPhone or iPad to AirPlay-compatible Apple TVs, smart TVs, speakers, and Macs, as well as certain third-party speakers and smart TVs, for seamless data transfer. AirPlay operates on a peer-to-peer basis, connecting your Apple devices through the local network. It uses a combination of technologies, including Real-Time Transport Protocol (RTP) for streaming audio and video and Bonjour for device discovery. Simply put, when you use AirPlay, your device sends a stream of data and then

Develop WeChat applet using Python Develop WeChat applet using Python Jun 17, 2023 pm 06:34 PM

With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine

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.

Can small programs use react? Can small programs use react? Dec 29, 2022 am 11:06 AM

Mini programs can use react. How to use it: 1. Implement a renderer based on "react-reconciler" and generate a DSL; 2. Create a mini program component to parse and render DSL; 3. Install npm and execute the developer Build npm in the tool; 4. Introduce the package into your own page, and then use the API to complete the development.

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Alipay launched the 'Chinese Character Picking-Rare Characters' mini program to collect and supplement the rare character library Oct 31, 2023 pm 09:25 PM

According to news from this site on October 31, on May 27 this year, Ant Group announced the launch of the "Chinese Character Picking Project", and recently ushered in new progress: Alipay launched the "Chinese Character Picking-Uncommon Characters" mini program to collect collections from the society Rare characters supplement the rare character library and provide different input experiences for rare characters to help improve the rare character input method in Alipay. Currently, users can enter the "Uncommon Characters" applet by searching for keywords such as "Chinese character pick-up" and "rare characters". In the mini program, users can submit pictures of rare characters that have not been recognized and entered by the system. After confirmation, Alipay engineers will make additional entries into the font library. This website noticed that users can also experience the latest word-splitting input method in the mini program. This input method is designed for rare words with unclear pronunciation. User dismantling

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.

See all articles