微信小程序?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">錄音開(kāi)始(aac)</button> <button class="tui-menu-list" bindtap="startRecordMp3" type="primary">錄音開(kāi)始(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;
}
開(kāi)始錄音和停止錄音
// pages/record/record.js
Page({
/**
* 頁(yè)面的初始數(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()
}
})
效果圖:

以上就是本文的全部?jī)?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)畫(huà)效果實(shí)例
- 微信小程序錄音文件格式silk遇到的問(wèn)題及解決方法
- 微信小程序錄音與播放錄音功能
- 微信小程序開(kāi)發(fā)之錄音機(jī) 音頻播放 動(dòng)畫(huà)實(shí)例 (真機(jī)可用)
- 微信小程序-圖片、錄音、音頻播放、音樂(lè)播放、視頻、文件代碼實(shí)例
- 微信小程序?qū)崿F(xiàn)錄音播放錄音功能
相關(guān)文章
JS+CSS實(shí)現(xiàn)仿支付寶菜單選中效果代碼
這篇文章主要介紹了JS+CSS實(shí)現(xiàn)仿支付寶菜單選中效果代碼,涉及JavaScript基于鼠標(biāo)事件動(dòng)態(tài)設(shè)置頁(yè)面css樣式的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09
關(guān)于flash遮蓋div浮動(dòng)層的解決方法
關(guān)于flash遮蓋div浮動(dòng)層2010-07-07
微信小程序?qū)崿F(xiàn)客服功能(客服消息)的全過(guò)程
在最近做的微信小程序中需要實(shí)現(xiàn)一個(gè)自帶的客服功能,下面這篇文章主要給大家介紹了關(guān)于微信小程序?qū)崿F(xiàn)客服功能(客服消息)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
JavaScript中Window對(duì)象的屬性及事件
這篇文章主要介紹了JavaScript中Window對(duì)象的屬性及事件 的相關(guān)資料,需要的朋友可以參考下2015-12-12
JS實(shí)現(xiàn)判斷對(duì)象是否為空對(duì)象的5種方法
這篇文章主要介紹了JS實(shí)現(xiàn)判斷對(duì)象是否為空對(duì)象的5種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
js實(shí)現(xiàn)隨機(jī)點(diǎn)名器精簡(jiǎn)版
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)隨機(jī)點(diǎn)名器的精簡(jiǎn)版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06

