微信小程序录音和头像上传

录音:

WXML

html 复制代码
<view class="box4">{{time}}</view>
<button bind:tap="recorderBtn">开始录音</button>
<button bind:tap="removeBtn">结束录音</button>
<button bind:tap="playBtn">播放录音</button>

JS

javascript 复制代码
Page({
  data:{
    time:0,
    clearTime:"",
    fileText:"",
  },
  recorderBtn(){
    this.data.clearTime = setInterval(()=>{
      this.data.time += 1;
      this.setData({time:this.data.time});
    },1000);
    a.start()
  },
  removeBtn(){
    clearInterval(this.data.clearTime);
    this.setData({time:0})
    a.stop();
    a.onStop((res)=>{
      this.data.fileText = res.tempFilePath;
    })
  },
  playBtn(){
    b.src = this.data.fileText;
    b.play();
  },

头像上传:

wxml

html 复制代码
<button class="avatar-wrapper" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar">
  <image class="avatar" src="{{ avatarUrl }}" />
</button>

wxss

css 复制代码
.avatar-wrapper {
  width: 160rpx;
  height: 160rpx;
  padding: 0;
  background: none;
}
.avatar {
  width: 160rpx;
  height: 160rpx;
  border-radius: 20rpx;
}

js

javascript 复制代码
 const defaultAvatar = '../../images/banner.jpg';
Page({
  data:{
    avatarUrl:defaultAvatar,}
)},

onChooseAvatar(e){
    console.log(e);
    const { avatarUrl } = e.detail
    this.setData({ avatarUrl })
  },
相关推荐
澄江静如练_4 小时前
微信小程序发体验版
微信小程序·小程序
流口水的兔子8 小时前
作为一个新手,如果让你去用【微信小程序通过BLE实现与设备通讯】,你会怎么做,
前端·物联网·微信小程序
一念杂记8 小时前
免费开源!微信小程序商城源码,快速搭建你的线上商城系统!
微信小程序·uni-app
张晓~183399481219 小时前
数字人源码部署流程分享--- PC+小程序融合方案
javascript·小程序·矩阵·aigc·文心一言·html5
The_era_achievs_hero11 小时前
微信小程序61~70
微信小程序·小程序
编程猪猪侠12 小时前
Taro+Vue3实现微信小程序富文本编辑器组件开发指南
vue.js·微信小程序·taro
汤姆yu1 天前
基于微信小程序的学校招生系统
微信小程序·小程序·招生小程序
说私域1 天前
基于开源AI智能名片链动2+1模式的S2B2C商城小程序:门店私域流量与视频号直播融合的生态创新研究
人工智能·小程序·开源
说私域1 天前
传统微商困境与开源链动2+1模式、AI智能名片及S2B2C商城小程序的转型破局
人工智能·小程序·开源
一渊之隔1 天前
微信小程序在用户拒绝授权后无法使用wx.opensetting再次获取定位授权
微信小程序·小程序