


With the development of mobile Internet technology, the development of mobile applications has become a necessary skill. Cross-platform development based on the uniapp framework optimizes developers' work efficiency. However, when implementing the recording function in uniapp, we may encounter some errors. Let’s take a look at these problems and their solutions.
Question 1: wx api is not declared or is not in the current module
First of all, we need to make it clear: uniapp is built on the basis of the vue framework, so its API part is the same as the vue API akin. If you encounter this problem, the reason is because we did not declare it after introducing the wx api.
Solution:
We need to introduce wx api into vue and declare it in the code before it can be used. The sample code is as follows:
import wx from 'uni-app/weixin.js'; export default{ data(){ return { recoderManager:null // 声明参数 } }, //在mounted部分进行wx api的声明 mounted(){ this.recoderManager = wx.getRecorderManager() } }
Question 2: recorder.start is not a function
This problem is obvious, that is, when we call recorder.start(), an error is reported. The reason is that we did not instantiate the recorderManager correctly.
Solution:
We need to instantiate wx api in the mounted part. Refer to the code below:
import wx from 'uni-app/weixin.js'; export default{ data(){ return { recoderManager:null // 声明参数 } }, //在mounted部分进行wx api的实例化 mounted(){ this.recoderManager = wx.getRecorderManager() }, methods:{ //在该方法中可以调用 start()方法 recoding(){ this.recoderManager.start({ //注意参数 duration:60000, format:'mp3' }); //当录音结束后触发该函数 this.recoderManager.onStop((res)=>{ var voice = res.tempFilePath //得到当前录音的文件路径 }) }, } }
Question 3: recorder.start fail: start audiomanager unsuccessfully
This problem may occur on iOS devices. The reason is that the current browser does not support it, or the audio permission is disabled. The solution is as follows:
Solution:
We need to enter the settings page and check whether the current application has obtained audio permissions. If the audio permission is disabled, we need to enable it. In addition, we can try to upgrade the browser version, which may solve such problems.
The above are three common problems and their solutions when uniapp implements the recording function. If you follow the above steps, you should be able to avoid these problems.
The above is the detailed content of What should I do if I get an error when implementing the recording function in uniapp?. For more information, please follow other related articles on the PHP Chinese website!

This article details uni-app's local storage APIs (uni.setStorageSync(), uni.getStorageSync(), and their async counterparts), emphasizing best practices like using descriptive keys, limiting data size, and handling JSON parsing. It stresses that lo

This article details making and securing API requests within uni-app using uni.request or Axios. It covers handling JSON responses, best security practices (HTTPS, authentication, input validation), troubleshooting failures (network issues, CORS, s

This article details uni-app's geolocation APIs, focusing on uni.getLocation(). It addresses common pitfalls like incorrect coordinate systems (gcj02 vs. wgs84) and permission issues. Improving location accuracy via averaging readings and handling

This article compares Vuex and Pinia for state management in uni-app. It details their features, implementation, and best practices, highlighting Pinia's simplicity versus Vuex's structure. The choice depends on project complexity, with Pinia suita

The article details how to integrate social sharing into uni-app projects using uni.share API, covering setup, configuration, and testing across platforms like WeChat and Weibo.

This article explains uni-app's easycom feature, automating component registration. It details configuration, including autoscan and custom component mapping, highlighting benefits like reduced boilerplate, improved speed, and enhanced readability.

Article discusses using Sass and Less preprocessors in uni-app, detailing setup, benefits, and dual usage. Main focus is on configuration and advantages.[159 characters]

This article details uni.request API in uni-app for making HTTP requests. It covers basic usage, advanced options (methods, headers, data types), robust error handling techniques (fail callbacks, status code checks), and integration with authenticat


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool