录音:
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 })
},