博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信小程序demo:QQ音乐;音乐搜索,音乐列表及播放停止
阅读量:4085 次
发布时间:2019-05-25

本文共 2504 字,大约阅读时间需要 8 分钟。


 


代码示例:
[AppleScript] 
纯文本查看 
复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var util
=
require
(
'..
/
..
/
utils
/
util.js'
)
 
var app
=
getApp
(
)
 
Page
(
{
    
data
:
{
        
playingSong
:
{
}
,
        
songUrl
:
''
,
        
songImg
:
''
,
        
songState
:
{
            
progress
:
0
,
            
currentPosition
:
'
00
:
00
'
,
            
duration
:
'
00
:
00
'
        
}
,
        
isPlaying
:
true
,
        
lyric
:
''
    
}
,
    
onLoad
:
function
(
)
{
        
console.
log
(
'playsong onLoad'
)
;
 
        
let
that
=
this;
        
let songdata
=
app.globalData.songData;
         
        
that
.setData
(
{
            
playingSong
:
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
)
{
                
/
/
do something
            
}
        
}
)
;
    
}
,
    
onReady
:
function
(
)
{
        
console.
log
(
'playsong onReady'
)
;
        
let
that
=
this;
        
that
.songPlay
(
)
;
 
        
wx.onBackgroundAudioPlay
(
function
(
)
{
            
console.
log
(
'播放了'
)
;
            
that
.songPlay
(
)
;
        
}
)
;
    
}
,
    
timeToString
:
function
(
duration
)
{
        
let str
=
'';
        
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
;
        
return
str;
    
}
,
    
songPlay
:
function
(
)
{
        
let
that
=
this;
        
let inv
=
setInterval
(
function
(
)
{
            
wx.getBackgroundAudioPlayerState
(
{
                
success
:
function
(
res
)
{
                    
if
(
res.status
=
=
1
)
{
                        
that
.setData
(
{
                            
isPlaying
:
true
,
                            
songState
:
{
                                
progress
:
res.currentPosition
/
res.duration
*
100
,
                                
currentPosition
:
that
.timeToString
(
res.currentPosition
)
,
                                
duration
:
that
.timeToString
(
res.duration
)
                            
}
                        
}
)
                    
}
else
{
                        
that
.setData
(
{
                            
isPlaying
:
false
                        
}
)
;
                        
clearInterval
(
inv
)
;
                    
}
                
}
            
}
)
;
        
}
,
1000
)
;
    
}
,
    
songToggle
:
function
(
)
{
        
let
that
=
this;
 
        
if
(
that
.
data
.isPlaying
)
{
            
wx.pauseBackgroundAudio
(
)
;
        
}
else
{
            
wx.playBackgroundAudio
(
{
                
title
:
that
.
data
.playingSong.songname
,
                
coverImgUrl
:
that
.
data
.songImg
            
}
)
;
        
}
;
 
        
that
.songPlay
(
)
;
    
}
}
)

项目地址及下载:

本帖隐藏的内容

https://github.com/linima/wx_qqmusic

 
 (34.5 KB, 下载次数: 5)

转载地址:http://snhni.baihongyu.com/

你可能感兴趣的文章
ES7的Async/Await
查看>>
React Native WebView组件实现的BarCode(条形码)、(QRCode)二维码
查看>>
每个人都能做的网易云音乐[vue全家桶]
查看>>
JavaScript专题之数组去重
查看>>
Immutable.js 以及在 react+redux 项目中的实践
查看>>
Vue2.0全家桶仿腾讯课堂(移动端)
查看>>
React+Redux系列教程
查看>>
react-native 自定义倒计时按钮
查看>>
19 个 JavaScript 常用的简写技术
查看>>
ES6这些就够了
查看>>
微信小程序:支付系列专辑(开发指南+精品Demo)
查看>>
iOS应用间相互跳转
查看>>
iOS开发之支付宝集成
查看>>
iOS开发 支付之银联支付集成
查看>>
iOS开发支付集成之微信支付
查看>>
浅谈JavaScript--声明提升
查看>>
React Native 图片组件的一些常见问题汇总
查看>>
webpack4.0各个击破(5)—— Module篇
查看>>
webpack4.0各个击破(6)—— Loader篇
查看>>
React性能优化
查看>>