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

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

 更新時間:2022年07月07日 09:06:56   作者:In?Heaven  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)播放音頻功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

功能描述:一進(jìn)頁面就會播放音樂,點擊暫停再次點擊后可以開始播放,退出頁面后播放停止。

HTML:

<view class="musicd">
? ? <image src="/resource/images/mic1.png" wx:if="{{isPlay}}" bindtap="audioPause"></image>
? ? <image src="/resource/images/mic2.png" wx:else bindtap="audioPlay"></image>
</view>
data:{
?? ?isPlay: true,
? ? srcMic: 'zzzzz.mp3'
}

onLoad: function (t) {
?? ?this.audioPlay();
},
//播放語音
? yuyinPlay: function (e) {
? ? let that = this
? ? //創(chuàng)建內(nèi)部 audio 上下文 InnerAudioContext 對象。
? ? that.innerAudioContext = wx.createInnerAudioContext();
? ? that.innerAudioContext.onError(function (res) {
? ? })
? ? if ((that.data.srcMic == '') || (that.data.srcMic == undefined)) return;

? ? that.innerAudioContext.src = that.data.srcMic //設(shè)置音頻地址
? ? this.innerAudioContext.play(); //播放音頻
? },
? //播放
? audioPlay() {
? ? this.yuyinPlay();
? ? this.setData({
? ? ? isPlay: true
? ? })
? },
? // 停止播放
? audioPause() {
? ? this.setData({
? ? ? isPlay: false
? ? })
? ? this.innerAudioContext.pause();//暫停音頻?

? },
? // 結(jié)束語音
? end: function (e) {
? ? let that = this
? ? if ((that.data.src) || (that.data.src != undefined)) return
? ? that.innerAudioContext.pause();//暫停音頻?
? },

?onHide: function () {
? ? this.end();//暫停音頻
? },
? onUnload: function () {
? ? this.end();//暫停音頻
? },
.musicd {
? position: fixed;
? z-index: 9999;
? top: 10%;
? left: 4%;
}
.musicd image {
? width: 100rpx;
? height: 100rpx;
? z-index: 999;
}

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

相關(guān)文章

最新評論