


Example of implementing WeChat jssdk recording and playing voice using HTML5
HTML5 WeChat jssdk method of recording and playing voice 2 issues that need attention 1 It must be judged that the recording within 1 second is not counted. ps: it is too short to record. 2 If the recording exceeds 1 minute, you will find that the recording suddenly disappears, so you need to write wx.onVoiceRecordEnd. This will automatically start after 1 minute and then write the upload data.
前端代码如下
$('.luyin').on('touchstart',function () { wx.startRecord({ success: function(){ START = new Date().getTime(); wx.onVoiceRecordEnd({ // 录音时间超过一分钟没有停止的时候会执行 complete 回调 complete: function (res) { alert('最多只能录制一分钟'); var localId = res.localId; uploadluyin(localId,60000); } }); }, cancel: function () { alert('用户拒绝授权录音'); return false; } }); }) $('.luyin').on('touchend',function () { END = new Date().getTime(); //录音时间 luyintime=END - START; if(luyintime < 2000){ END = 0; START = 0; wx.stopRecord({}); alert('录音时间不能少于2秒'); return false; //小于300ms,不录音 }else { wx.stopRecord({ success: function (res) { localId = res.localId; uploadluyin(localId,luyintime); } }); } }) function uploadluyin(localId,luyintime) { wx.uploadVoice({ localId: localId, // 需要上传的音频的本地ID,由stopRecord接口获得 isShowProgressTips: 1, // 默认为1,显示进度提示 success: function (res) { var serverId = res.serverId; // 返回音频的服务器端ID console.log(serverId); $.post("/home/xishanluyin/scyuyin", { "serverId": serverId, "luyintime": luyintime }, function (data) { if (data.success == 1) { alert('录音成功'); } else { alert(data.msg); } }, "json"); } }) }
The core code of the back-end code is as follows. Just write it directly into mp3
$ft = copy("http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$accessToken}&media_id={$imgServerId}", APP_PATH . "/../Public/{$project}/upload/{$imgServerId}.mp3");
Then play it with Baofeng Video
Related recommendations:
Front-end WeChat share jssdk config :invalid signature Solution to signature error
thinkPHP WeChat sharing interface JSSDK example explanation
WeChat jssdk sharing function example tutorial
The above is the detailed content of Example of implementing WeChat jssdk recording and playing voice using HTML5. For more information, please follow other related articles on the PHP Chinese website!

H5 is HTML5, the fifth version of HTML. HTML5 improves the expressiveness and interactivity of web pages, introduces new features such as semantic tags, multimedia support, offline storage and Canvas drawing, and promotes the development of Web technology.

Accessibility and compliance with network standards are essential to the website. 1) Accessibility ensures that all users have equal access to the website, 2) Network standards follow to improve accessibility and consistency of the website, 3) Accessibility requires the use of semantic HTML, keyboard navigation, color contrast and alternative text, 4) Following these principles is not only a moral and legal requirement, but also amplifying user base.

The H5 tag in HTML is a fifth-level title that is used to tag smaller titles or sub-titles. 1) The H5 tag helps refine content hierarchy and improve readability and SEO. 2) Combined with CSS, you can customize the style to enhance the visual effect. 3) Use H5 tags reasonably to avoid abuse and ensure the logical content structure.

The methods of building a website in HTML5 include: 1. Use semantic tags to define the web page structure, such as, , etc.; 2. Embed multimedia content, use and tags; 3. Apply advanced functions such as form verification and local storage. Through these steps, you can create a modern web page with clear structure and rich features.

A reasonable H5 code structure allows the page to stand out among a lot of content. 1) Use semantic labels such as, etc. to organize content to make the structure clear. 2) Control the rendering effect of pages on different devices through CSS layout such as Flexbox or Grid. 3) Implement responsive design to ensure that the page adapts to different screen sizes.

The main differences between HTML5 (H5) and older versions of HTML include: 1) H5 introduces semantic tags, 2) supports multimedia content, and 3) provides offline storage functions. H5 enhances the functionality and expressiveness of web pages through new tags and APIs, such as and tags, improving user experience and SEO effects, but need to pay attention to compatibility issues.

The difference between H5 and HTML5 is: 1) HTML5 is a web page standard that defines structure and content; 2) H5 is a mobile web application based on HTML5, suitable for rapid development and marketing.

The core features of HTML5 include semantic tags, multimedia support, form enhancement, offline storage and local storage. 1. Semantic tags such as, improve code readability and SEO effect. 2. Multimedia support simplifies the process of embedding media content through and tags. 3. Form Enhancement introduces new input types and verification properties, simplifying form development. 4. Offline storage and local storage improve web page performance and user experience through ApplicationCache and localStorage.


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

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

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

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.

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.

Notepad++7.3.1
Easy-to-use and free code editor

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