這期內(nèi)容當中小編將會給大家?guī)碛嘘P(guān)怎么在微信小程序中實現(xiàn)一個音樂播放器,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比遂寧網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式遂寧網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋遂寧地區(qū)。費用合理售后完善,十年實體公司更值得信賴。
wxss文件
//index.wxss .button-style{ background-color: #eee; border-radius: 8rpx; margin: 20rpx; }
只是頂一個簡單的按鈕的圓角和間距,顏色這個我還是用primary這個小綠色。
下面是index.wxml文件
//index.wxml <button class="button-style" type="primary" bindtap="listenerButtonPlay">播放</button> <button class="button-style" type="primary" bindtap="listenerButtonPause">暫停</button> <button class="button-style" type="primary" bindtap="listenerButtonSeek">設(shè)置播放進度</button> <button class="button-style" type="primary" bindtap="listenerButtonStop">停止播放</button> <button class="button-style" type="primary" bindtap="listenerButtonGetPlayState">獲取播放狀態(tài)</button>
沒辦法,用開發(fā)者工具打出來就是這樣的丑格式
下面是重點index.js
//index.js //獲取應(yīng)用實例 var app = getApp() Page({ data:{ }, //播放 listenerButtonPlay:function(){ wx.playBackgroundAudio({ dataUrl: 'http://ac-5g9r20ds.clouddn.com/e54ad7f0a834b9c07ec6.mp3', title:'李宗盛', //圖片地址地址 coverImgUrl:'http://ac-5g9r20ds.clouddn.com/63bedb5f584234b6827c.jpg' }) }, //監(jiān)聽button暫停按鈕 listenerButtonPause:function(){ wx.pauseBackgroundAudio({ }); console.log('暫停播放') }, /** * 播放狀態(tài) */ listenerButtonGetPlayState:function(){ wx.getBackgroundAudioPlayerState({ success: function(res){ // success //duration 選定音頻的長度(單位:s),只有在當前有音樂播放時返回 console.log('duration:' + res.duration) console.log('currentPosition:' + res.currentPosition) //status 播放狀態(tài)(2:沒有音樂在播放,1:播放中,0:暫停中) console.log('status:' + res.status) console.log('downloadPercent:' + res.downloadPercent) //dataUrl 歌曲數(shù)據(jù)鏈接,只有在當前有音樂播放時返回 console.log('dataUrl:' + res.dataUrl) }, fail: function() { // fail }, complete: function() { // complete } }) }, /** * 設(shè)置進度 */ listenerButtonSeek:function(){ wx.seekBackgroundAudio({ position: 40 }) }, /** * 停止播放 */ listenerButtonStop:function(){ wx.stopBackgroundAudio({ }) console.log('停止播放') }, onLoad:function(options){ // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù) /** * 監(jiān)聽音樂播放 */ wx.onBackgroundAudioPlay(function() { // callback console.log('onBackgroundAudioPlay') }) /** * 監(jiān)聽音樂暫停 */ wx.onBackgroundAudioPause(function() { // callback console.log('onBackgroundAudioPause') }) /** * 監(jiān)聽音樂停止 */ wx.onBackgroundAudioStop(function() { // callback console.log('onBackgroundAudioStop') }) } })
上述就是小編為大家分享的怎么在微信小程序中實現(xiàn)一個音樂播放器了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
文章題目:怎么在微信小程序中實現(xiàn)一個音樂播放器
網(wǎng)頁地址:http://muchs.cn/article6/pgdsig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、云服務(wù)器、品牌網(wǎng)站制作、移動網(wǎng)站建設(shè)、軟件開發(fā)、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)