audio音频组件
audio.wxml文件
<view class="container">
<audio poster="{{poster}}" name="{{name}}" author="{{author}}" src="{{src}}" action="{{action}}" controls loop></audio>
<view class="button-wrap">
<button type="primary" bindtap="audioPlay">播放</button>
</view>
<view class="button-wrap">
<button type="primary" bindtap="audioPause">暂停</button>
</view>
<view class="button-wrap">
<button type="primary" bindtap="audioPlaybackRateSpeedUp">调为2倍速</button>
</view>
<view class="button-wrap">
<button type="primary" bindtap="audioPlaybackRateNormal">调为1倍速</button>
</view>
<view class="button-wrap">
<button type="primary" bindtap="audioPlaybackRateSlowDown">调为0.5倍速</button>
</view>
<view class="button-wrap">
<button type="primary" bindtap="audio14">设置当前播放时间为14秒</button>
</view>
<view class="button-wrap">
<button type="primary" bindtap="audioStart">回到开头</button>
</view>
</view>
audio.js文件
Page({
/**
* 页面的初始数据
*/
data: {
poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',
name:'此时此刻',
author:'许巍',
src: 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46',
},
audioPlay:function(){
this.setData({
action:{
method:'play'
}
})
},
audioPause:function(){
this.setData({
action:{
method:'pause'
}
})
},
audioPlaybackRateSpeedUp: function () {
this.setData({
action: {
method: 'setPlaybackRate',
data:2
}
})
},
audioPlaybackRateNormal: function () {
this.setData({
action: {
method: 'setPlaybackRate',
data:1
}
})
},
audioPlaybackRateSlowDown: function () {
this.setData({
action: {
method: 'setPlaybackRate',
data: 0.5
}
})
},
audio14: function () {
this.setData({
action: {
method: 'setCurrentTime',
data: 14
}
})
},
auduoStart: function () {
this.setData({
action: {
method: 'setCurrentTime',
data: 0
}
})
}
})