用户
 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,登录网站

2516

主题

7206

帖子

2万

积分

版主

Rank: 7Rank: 7Rank: 7

积分
24606
2017-1-6 19:31:09 天下雪原创达人 造轮子 版主 楼主 2142600
1.png 2.png 3.png 4.png 5.png


代码示例:
[AppleScript] 纯文本查看 复制代码
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();
        }
})

项目地址及下载:
https://github.com/linima/wx_qqmusic
wx_qqmusic-master (1).zip (34.66 KB, 下载次数: 406)
有问题请在本站内搜索相应关键词,假如无法解决请在综合交流区内发帖咨询,发帖时请提供详细的问题描述、相关图片及代码。
binxchen1010 发表于 2017-1-6 21:38
请继续上传好的demo,我会不断的支持并且为作者打气

感谢支持,欢迎同学在 别人需要demo的时候宣传一下我们
有问题请在本站内搜索相应关键词,假如无法解决请在综合交流区内发帖咨询,发帖时请提供详细的问题描述、相关图片及代码。
请继续上传好的demo,我会不断的支持并且为作者打气
正在找这个  学习了
好东西,学习
项目地址过来看看
感谢楼主无私分享
谢谢分享
不断的关注  学习
[demo]微信小程序demo:QQ音乐;音乐搜索,音乐列表及播放停止
赞一个
刚开始学习,看看,赞一个
学习
您需要登录后才可以回帖 登录 | 立即注册