欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)錄音

 更新時(shí)間:2022年06月24日 14:06:31   作者:示羊online  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)錄音,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)錄音的具體代碼,供大家參考,具體內(nèi)容如下

為錄音

錄音中

wxml:

<!-- 開始錄音 -->
<image src="/img/add_voice.png" class="add-voice" wx:if="{{record == 0 }}" bindtap="startRecord"></image>
?
<!-- 錄音中 -->
<block wx:if="{{record == 1}}">
<view class='audio'>
? <view class='laudio_btn' bindtap='remove'>
? ? <image src='/img/btn_close2.png' style='width:26rpx;height:25rpx;'></image>
? </view>
? <text class='laudio_text1'>|</text>
? <text class='laudio_text2'>{{formatedRecordTime}}</text>
? <view class='laudio_pro'>
? ? <image src='/img/btn_play2.png' style='width:100%;height:100%' catchtap='keep' wx:if="{{keep}}"></image>
? ? <image src='/img/btn_play3.png' style='width:100%;height:100%' catchtap='pause' wx:else></image>
? </view>
? <text class='audio_text' catchtap='stopRecord'>完成</text>
</view>
</block>

wxss:

.add-voice {
? width: 158rpx;
? height: 158rpx;
}
?
.audio {
? display: flex;
? position: relative;
? height: 140rpx;
? line-height: 140rpx;
? background: #f7f7f7;
? width: 96%;
}
?
/* 傳語音 */
.audio{
? display: flex;
? position: relative;
? height:140rpx;
? line-height: 140rpx;
? background: #f7f7f7;
? width: 96%;
}
/* 錄語音 */
.laudio_btn{
? /* width:26rpx;
? height:26rpx; */
? margin-left:42rpx
}
.audio_img{
? position: absolute;
? /* top:-15rpx; */
? /* right:-15rpx; */
? right: 0;
? width:30rpx;
? height:30rpx;
}
.audio_btn{
? width:88rpx;
? height:88rpx;
? margin-top:28rpx;
? ?margin-left:16rpx
}
.audio_pro{
? margin-top:36rpx;
? margin-left:20rpx;
? width:300rpx;
}
.audio_text{
? font-weight: bold;
? margin-left:50rpx;
? color:#90BED5;
? font-size: 10pt
}
.laudio_text1{
? font-size: 26rpx;
? margin-left:20rpx;
? color: #90BED5
}
.laudio_text2{
? font-weight: bold;
? font-size: 26rpx;
? margin-left:20rpx;
? color: #F8624E;
? width: 381rpx;
}
.laudio_pro{
? width:88rpx;
? height:88rpx;
? margin-top:28rpx;
}

js:

var util = require('../../utils/count.js') //計(jì)算時(shí)分秒函數(shù)
let radio = wx.getRecorderManager(); //創(chuàng)建錄音
const app = getApp()
?
var recordTimeInterval; //錄音 時(shí)分秒 '00:00'
?
Page({
? data: {
? ? record : 0, //未錄音
? ? formatedRecordTime: '00:00',
? ? keep: true,
? ? recordTime: 0
? },
? //開始錄音
? startRecord: function () {
? ? var that = this
? ? this.setData({ record: 1 })
? ? recordTimeInterval = setInterval(function () { //計(jì)算時(shí)分秒
? ? ? var recordTime = that.data.recordTime += 1
? ? ? that.setData({
? ? ? ? formatedRecordTime: util.formatTime(that.data.recordTime),
? ? ? ? recordTime: recordTime
? ? ? })
? ? }, 1000)
? ? const options = {
? ? ? duration: 30000, //錄音
? ? ? sampleRate: 44100,
? ? ? numberOfChannels: 1,
? ? ? encodeBitRate: 192000,
? ? ? format: 'mp3'
? ? }
? ? radio.start(options); //開始錄音
? ? radio.onStart((res => {
? ? ? console.log('監(jiān)聽錄音', res)
? ? }));//監(jiān)聽錄音事件
? },
? //暫停錄音
? keep() {
? ? radio.resume();
? ? this.setData({ keep: false })
? ? clearInterval(recordTimeInterval);
? },
? //繼續(xù)錄音
? pause() {
? ? var that = this
? ? this.setData({ keep: true, })
? ? recordTimeInterval = setInterval(function () { //計(jì)算時(shí)分秒
? ? ? var recordTime = that.data.recordTime += 1
? ? ? that.setData({
? ? ? ? formatedRecordTime: util.formatTime(that.data.recordTime),
? ? ? ? recordTime: recordTime
? ? ? })
? ? }, 1000)
? },
? //結(jié)束錄音
? stopRecord: function () {
? ? console.log('錄音結(jié)束了')
? ? var that = this;
? ? clearInterval(recordTimeInterval);
? ? radio.stop(); //錄音結(jié)束
? ? radio.onStop((res) => { //錄音結(jié)束
? ? ? // that.stopRecord
? ? ? console.log('錄音結(jié)束', res);
? ? ? this.setData({
? ? ? ? record: res.tempFilePath,
? ? ? ? musicUrl: res.tempFilePath, //錄音音頻
? ? ? ? duration: res.duration, //音頻時(shí)長時(shí)間戳
? ? ? ? record: true,
? ? ? })
? ? })
? },
? //取消錄音
? remove() {
? ? radio.stop(); //結(jié)束錄音
? ? this.setData({ record: 0, recordTime: 0, play: false })
? ? clearInterval(recordTimeInterval);
? },
})

utils/count.js

function formatTime(time) {
? if (typeof time !== 'number' || time < 0) {
? ? return time
? }
?
? var hour = parseInt(time / 3600)
? time = time % 3600
? var minute = parseInt(time / 60)
? time = time % 60
? var second = time
?
? return ([hour, minute, second]).map(function (n) {
? ? n = n.toString()
? ? return n[1] ? n : '0' + n
? }).join(':')
}
?
function formatLocation(longitude, latitude) {
? if (typeof longitude === 'string' && typeof latitude === 'string') {
? ? longitude = parseFloat(longitude)
? ? latitude = parseFloat(latitude)
? }
?
? longitude = longitude.toFixed(2)
? latitude = latitude.toFixed(2)
?
? return {
? ? longitude: longitude.toString().split('.'),
? ? latitude: latitude.toString().split('.')
? }
}
?
module.exports = {
? formatTime: formatTime,
? formatLocation: formatLocation
}

播放音頻:微信小程序?qū)崿F(xiàn)播放音頻

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • JavaScript  函數(shù)語法詳解

    JavaScript 函數(shù)語法詳解

    本文結(jié)合前面發(fā)布的文章,詳細(xì)介紹了javascript的函數(shù)語法,非常的詳盡,非常的實(shí)用,這里推薦給大家,是篇不可多得的文章
    2021-09-09
  • 不同瀏覽器javascript變量作用域的處理方法

    不同瀏覽器javascript變量作用域的處理方法

    javascript變量作用域在不同瀏覽器的實(shí)現(xiàn)處理代碼
    2008-09-09
  • JS利用時(shí)間戳倒計(jì)時(shí)的實(shí)現(xiàn)示例

    JS利用時(shí)間戳倒計(jì)時(shí)的實(shí)現(xiàn)示例

    這篇文章主要介紹了JS利用時(shí)間戳倒計(jì)時(shí)的實(shí)現(xiàn)示例,本文將提供代碼示例和詳細(xì)的步驟,幫助你實(shí)現(xiàn)一個(gè)簡單而實(shí)用的時(shí)間戳倒計(jì)時(shí),感興趣的可以了解一下
    2023-12-12
  • 小程序接入騰訊位置服務(wù)的詳細(xì)流程

    小程序接入騰訊位置服務(wù)的詳細(xì)流程

    這篇文章主要介紹了小程序接入騰訊位置服務(wù)的詳細(xì)流程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 微信小程序?qū)崿F(xiàn)圖片上傳功能的思路與源碼

    微信小程序?qū)崿F(xiàn)圖片上傳功能的思路與源碼

    我們?nèi)粘i_發(fā)中經(jīng)常需要用到圖片上傳功能,這篇文章主要給大家介紹了關(guān)于微信小程序?qū)崿F(xiàn)圖片上傳功能的思路與源碼的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • JS實(shí)現(xiàn)html頁面點(diǎn)擊下載文件的兩種方式

    JS實(shí)現(xiàn)html頁面點(diǎn)擊下載文件的兩種方式

    這篇文章主要介紹了JS實(shí)現(xiàn)html頁面點(diǎn)擊下載文件的兩種方式,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07
  • javascript 文檔的編碼問題解決

    javascript 文檔的編碼問題解決

    在引用與本頁面編碼格式不一樣的js文檔時(shí),如果被引用的js代碼有ASCII字符之外的字符,那么就會出現(xiàn)代碼錯(cuò)誤。
    2009-03-03
  • 淺聊一下TypeScript中的4種類型守衛(wèi)

    淺聊一下TypeScript中的4種類型守衛(wèi)

    類型守衛(wèi)是TypeScript中特有的用于在運(yùn)行時(shí)檢查類型的方式,它顯式的將javascript代碼按類型劃分,從而確保了運(yùn)行安全,下面我們就來簡單聊聊TypeScript中的4種類型守衛(wèi)吧
    2023-08-08
  • js單頁hash路由原理與應(yīng)用實(shí)戰(zhàn)詳解

    js單頁hash路由原理與應(yīng)用實(shí)戰(zhàn)詳解

    本篇文章主要介紹了js單頁hash路由原理與應(yīng)用實(shí)戰(zhàn)詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • 微信小程序返回上一頁的各種方法實(shí)例

    微信小程序返回上一頁的各種方法實(shí)例

    在開發(fā)小程序的時(shí)候我們總是能遇到各種奇怪的需求,下面這篇文章主要給大家介紹了關(guān)于微信小程序返回上一頁的各種方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06

最新評論