最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序實現(xiàn)錄音

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

本文實例為大家分享了微信小程序實現(xiàn)錄音的具體代碼,供大家參考,具體內容如下

為錄音

錄音中

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') //計算時分秒函數(shù)
let radio = wx.getRecorderManager(); //創(chuàng)建錄音
const app = getApp()
?
var recordTimeInterval; //錄音 時分秒 '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 () { //計算時分秒
? ? ? 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 () { //計算時分秒
? ? ? var recordTime = that.data.recordTime += 1
? ? ? that.setData({
? ? ? ? formatedRecordTime: util.formatTime(that.data.recordTime),
? ? ? ? recordTime: recordTime
? ? ? })
? ? }, 1000)
? },
? //結束錄音
? stopRecord: function () {
? ? console.log('錄音結束了')
? ? var that = this;
? ? clearInterval(recordTimeInterval);
? ? radio.stop(); //錄音結束
? ? radio.onStop((res) => { //錄音結束
? ? ? // that.stopRecord
? ? ? console.log('錄音結束', res);
? ? ? this.setData({
? ? ? ? record: res.tempFilePath,
? ? ? ? musicUrl: res.tempFilePath, //錄音音頻
? ? ? ? duration: res.duration, //音頻時長時間戳
? ? ? ? record: true,
? ? ? })
? ? })
? },
? //取消錄音
? remove() {
? ? radio.stop(); //結束錄音
? ? 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
}

播放音頻:微信小程序實現(xiàn)播放音頻

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 根據(jù)判斷瀏覽器類型屏幕分辨率自動調用不同CSS的代碼

    根據(jù)判斷瀏覽器類型屏幕分辨率自動調用不同CSS的代碼

    根據(jù)判斷瀏覽器類型屏幕分辨率自動調用不同CSS的代碼...
    2007-02-02
  • JavaScript實現(xiàn)Fly Bird小游戲

    JavaScript實現(xiàn)Fly Bird小游戲

    這篇文章主要為大家詳細介紹了JavaScript實現(xiàn)Fly Bird小游戲的制作方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • 使用純JS代碼判斷字符串中有多少漢字的實現(xiàn)方法(超簡單實用)

    使用純JS代碼判斷字符串中有多少漢字的實現(xiàn)方法(超簡單實用)

    這篇文章主要給大家介紹了js判斷字符串中有多少漢字的實現(xiàn)方法然后給大家分享了使用JS判斷輸入字符串長度的兩種方法,非常不錯具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-11-11
  • js實現(xiàn)隨機點名器精簡版

    js實現(xiàn)隨機點名器精簡版

    這篇文章主要為大家詳細介紹了js實現(xiàn)隨機點名器的精簡版,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 微信小程序實現(xiàn)簡易計算器

    微信小程序實現(xiàn)簡易計算器

    這篇文章主要為大家詳細介紹了微信小程序實現(xiàn)簡易計算器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • js保留兩位小數(shù)最簡單的實現(xiàn)方法

    js保留兩位小數(shù)最簡單的實現(xiàn)方法

    JS數(shù)據(jù)格式化是在進行web前端開發(fā)時常碰到的事情,特別是在數(shù)據(jù)類型為Float的數(shù)據(jù)就需要特殊處理,如保留兩位小數(shù)、小數(shù)點后的數(shù)據(jù)是否需要四舍五入等等,下面這篇文章主要給大家介紹了關于js保留兩位小數(shù)最簡單的實現(xiàn)方法,需要的朋友可以參考下
    2023-05-05
  • 使用url-loader處理圖片等資源文件的方法步驟

    使用url-loader處理圖片等資源文件的方法步驟

    在Web開發(fā)中,處理圖片、字體等資源文件是一個常見的需求,傳統(tǒng)的做法是將這些資源文件放在靜態(tài)目錄中,然后在HTML或CSS中引用,然而,這種方法在構建工具(如Webpack)中并不總是最理想的,為了解決這個問題,可以使用url-loader,需要的朋友可以參考下
    2025-04-04
  • Javascript實現(xiàn)元素選擇器功能

    Javascript實現(xiàn)元素選擇器功能

    這篇文章主要為大家詳細介紹了Javascript實現(xiàn)元素選擇器功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • Javascript中常見的邏輯題和解決方法

    Javascript中常見的邏輯題和解決方法

    今天遇到了一些題,比較有意思和輕巧,而且加強運用一下了js原生語法,現(xiàn)在小編總結好后分享給大家,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-09-09
  • 深入理解es6塊級作用域的使用

    深入理解es6塊級作用域的使用

    這篇文章主要介紹了深入理解es6塊級作用域的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-03-03

最新評論

龙江县| 故城县| 若尔盖县| 东乡族自治县| 麻城市| 西林县| 巴中市| 渭南市| 新乡市| 镇安县| 且末县| 会理县| 吐鲁番市| 阿图什市| 东莞市| 屯门区| 黄石市| 辰溪县| 永胜县| 龙泉市| 张家界市| 台东市| 托克托县| 东光县| 固安县| 安仁县| 财经| 井陉县| 东阿县| 德保县| 射阳县| 台湾省| 崇仁县| 仪征市| 合水县| 巴青县| 监利县| 周口市| 庄浪县| 始兴县| 罗平县|