欢迎光临,了解微信小程序开发,就上易用通!

当前位置 : 易用通 > 小程序模板
QQ音乐;音乐搜索,音乐列表及播放停止QQ音乐;音乐搜索,音乐列表及播放停止
立即下载

QQ音乐;音乐搜索,音乐列表及播放停止

模板分类 : 小程序模板 模板编号 : Y958 源码文件 : 完全开源 下载权限 : VIP会员
模板大小 :  模板指数 :  更新时间 : 2018-03-16 11:48 模板等级 : ☆☆☆☆☆

模板截图:

QQ音乐;音乐搜索,音乐列表及播放停止(图1) QQ音乐;音乐搜索,音乐列表及播放停止(图2) QQ音乐;音乐搜索,音乐列表及播放停止(图3) QQ音乐;音乐搜索,音乐列表及播放停止(图4) QQ音乐;音乐搜索,音乐列表及播放停止(图5)  代码示例:
[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/C100' + songdata.songmid + '.m4a?fromtag=38',
                        songImg: 'http://y.gtimg.cn/music/photo_new/T002R150x150M000' + 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();
        }
})

加入收藏
立即下载
分享到微信朋友圈
X

免责声明:

1. 本站所有素材(未指定商用),仅限学习交流,请勿用于商业用途。
2. 本站所有小程序模板Demo和图片均来自用户分享上传和网络收集,模板和图片版权归原作者及原出处所有。
3. 未经合法授权,会员不得以任何形式发布、传播、复制、转售该素材。