本文共 2504 字,大约阅读时间需要 8 分钟。
代码示例: | var util = require ( '.. / .. / utils / util.js' ) currentPosition : ' 00 : 00 ' , console. log ( 'playsong onLoad' ) ; let songdata = app.globalData.songData; songUrl : 'http : / / ws.stream.qqmusic.qq.com / C 100 ' + songdata.songmid + '.m 4 a?fromtag = 38 ' , songImg : 'http : / / y.gtimg.cn / music / photo_new / T 002 R 150 x 150 M 000 ' + songdata.albummid + '.jpg' , let thatData = that . data ; wx.playBackgroundAudio ( { dataUrl : thatData.songUrl , title : thatData.playingSong.songname , coverImgUrl : thatData.songImg , success : function ( res ) { console. log ( 'playsong onReady' ) ; wx.onBackgroundAudioPlay ( function ( ) { timeToString : function ( duration ) { let minute = parseInt ( duration / 60 ) < 10 ? ( ' 0 ' + parseInt ( duration / 60 ) ) : ( parseInt ( duration / 60 ) ) ; let second = duration% 60 < 10 ? ( ' 0 ' + duration% 60 ) : ( duration% 60 ) ; str = minute + ' : ' + second ; songPlay : function ( ) { let inv = setInterval ( function ( ) { wx.getBackgroundAudioPlayerState ( { success : function ( res ) { if ( res.status = = 1 ) { progress : res.currentPosition / res.duration * 100 , currentPosition : that .timeToString ( res.currentPosition ) , duration : that .timeToString ( res.duration ) songToggle : function ( ) { if ( that . data .isPlaying ) { wx.pauseBackgroundAudio ( ) ; wx.playBackgroundAudio ( { title : that . data .playingSong.songname , coverImgUrl : that . data .songImg | 项目地址及下载: 本帖隐藏的内容 https://github.com/linima/wx_qqmusic (34.5 KB, 下载次数: 5) |
转载地址:http://snhni.baihongyu.com/