微信小程序?qū)崿F(xiàn)錄音Record功能
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)錄音Record功能的具體代碼,供大家參考,具體內(nèi)容如下
布局
<!--pages/record/record.wxml--> <view> <button class="tui-menu-list" bindtap="startRecordAac" type="primary">錄音開始(aac)</button> <button class="tui-menu-list" bindtap="startRecordMp3" type="primary">錄音開始(mp3)</button> <button class="tui-menu-list" bindtap="stopRecord" type="primary">錄音結(jié)束</button> <button class="tui-menu-list" bindtap="playRecord" type="primary">播放錄音</button> </view>
樣式:
/* pages/record/record.wxss */
.tui-menu-list{
flex-direction: row;
margin: 20rpx;
padding: 20rpx;
}
開始錄音和停止錄音
// pages/record/record.js
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
},
onLoad:function (options) {
var that = this
this.recorderManager = wx.getRecorderManager();
this.recorderManager.onError(function () {
that.tip("錄音失敗!");
})
this.recorderManager.onStop(function (res) {
that.setData({
src:res.tempFilePath
})
console.log(res.tempFilePath)
that.tip("錄音完成!")
})
this.innerAudioContext = wx.createInnerAudioContext()
this.innerAudioContext.onError((res) =>{
that.tip("播放錄音失敗!")
})
},
//提示
tip:function (msg) {
wx.showModal({
cancelColor: 'cancelColor',
title:'提示',
content:msg,
showCancel:false
})
},
//錄制aac
startRecordAac:function () {
this.recorderManager.start({
format:'aac'
})
},
//錄制mp3
startRecordMp3:function () {
this.recorderManager.start({
format:'mp3'
})
},
//停止錄音
stopRecord:function () {
this.recorderManager.stop()
},
//播放錄音
playRecord:function () {
var that = this
var src = this.data.src
if (src='') {
this.tip('請(qǐng)先錄音')
return
}
this.innerAudioContext.src = this.data.src
this.innerAudioContext.play()
}
})
效果圖:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序用戶后臺(tái)定位及錄音授權(quán)及請(qǐng)求示例
- 微信小程序?qū)崿F(xiàn)錄音與音頻播放功能
- 微信小程序錄音實(shí)現(xiàn)功能并上傳(使用node解析接收)
- 微信小程序?qū)崿F(xiàn)錄音功能
- 微信小程序?qū)崿F(xiàn)錄音時(shí)的麥克風(fēng)動(dòng)畫效果實(shí)例
- 微信小程序錄音文件格式silk遇到的問題及解決方法
- 微信小程序錄音與播放錄音功能
- 微信小程序開發(fā)之錄音機(jī) 音頻播放 動(dòng)畫實(shí)例 (真機(jī)可用)
- 微信小程序-圖片、錄音、音頻播放、音樂播放、視頻、文件代碼實(shí)例
- 微信小程序?qū)崿F(xiàn)錄音播放錄音功能
相關(guān)文章
JavaScript時(shí)間對(duì)象Date內(nèi)置構(gòu)造函數(shù)操作實(shí)例
這篇文章主要為大家介紹了JavaScript時(shí)間對(duì)象Date內(nèi)置構(gòu)造函數(shù)操作實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
JS實(shí)現(xiàn)改變HTML上文字顏色和內(nèi)容的方法
這篇文章主要介紹了JS實(shí)現(xiàn)改變HTML上文字顏色和內(nèi)容的方法,涉及JS數(shù)學(xué)運(yùn)算與頁面元素動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-12-12
利用Plupload.js解決大文件上傳問題, 帶進(jìn)度條和背景遮罩層
本篇文章主要介紹了c#+Plupload.js解決大容量文件上傳問題, 帶進(jìn)度條和背景遮罩層,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
js實(shí)現(xiàn)完全自定義可帶多級(jí)目錄的網(wǎng)頁鼠標(biāo)右鍵菜單方法
這篇文章主要介紹了js實(shí)現(xiàn)完全自定義可帶多級(jí)目錄的網(wǎng)頁鼠標(biāo)右鍵菜單方法,實(shí)例分析了javascript實(shí)現(xiàn)自定義網(wǎng)頁鼠標(biāo)右鍵彈出菜單的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-02-02
用 js 的 selection range 操作選擇區(qū)域內(nèi)容和圖片
本篇文章主要介紹了用js的selection range操作選擇區(qū)域內(nèi)容和圖片的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04

