App({
onLaunch: function () {
var that = this;
//播放列表中下一首
wx.onBackgroundAudioStop(function () {
if (that.globalData.globalStop) {
return;
}
if (that.globalData.playtype == 1) {
that.nextplay(1);
} else {
that.nextfm();
}
});
},
nextplay: function (t) {
//播放列表中下一首
this.preplay();
var list = this.globalData.list_am;
var index = this.globalData.index_am;
if (t == 1) {
index++;
} else {
index--;
}
index = index > list.length - 1 ? 0 : (index < 0 ? list.length - 1 : index);
this.globalData.curplay = list[index] || {};
this.globalData.index_am = index;
this.seekmusic(1)
},
nextfm: function () {
//下一首fm
this.preplay()
var that = this;
var list = that.globalData.list_fm;
var index = that.globalData.index_fm;
index++;
this.globalData.playtype = 2;
if (index > list.length - 1) {
that.getfm();
} else {
console.log("获取下一首fm")
that.globalData.index_fm = index;
that.globalData.curplay = list[index];
that.seekmusic(2);
}
},
preplay: function () {
//歌曲切换 停止当前音乐
this.globalData.globalStop = true;
wx.stopBackgroundAudio();
},
getfm: function () {
var that = this;
console.log("从新获取fm")
wx.request({
url: 'https://n.sqaiyan.com/fm?t=' + (new Date()).getTime(),
method: 'GET',
success: function (res) {
that.globalData.list_fm = res.data.data;
that.globalData.index_fm = 0;
that.globalData.curplay = res.data.data[0];
that.seekmusic(2);
}
})
},
stopmusic: function (type, cb) {
var that = this;
wx.pauseBackgroundAudio();
wx.getBackgroundAudioPlayerState({
complete: function (res) {
that.globalData.currentPosition = res.currentPosition || '0'
}
})
},
seekmusic: function (type, cb, seek) {
console.log("type:",type)
var that = this;
var m = this.globalData.curplay;
this.globalData.playtype = type;
if (type == 1) {
wx.request({
url: 'https://n.sqaiyan.com/song?id=' + that.globalData.curplay.id,
success: function (res) {
if (!res.data.songs[0].mp3Url) {
that.nextplay(1);
}
}
})
}
wx.playBackgroundAudio({
dataUrl: m.mp3Url,
title: m.name,
success: function (res) {
if (seek != undefined) {
wx.seekBackgroundAudio({ position: seek })
};
that.globalData.globalStop = false;
cb && cb();
},
fail: function () {
if (type == 1) {
that.nextplay(1)
} else {
that.nextfm();
}
}
})
},
shuffleplay: function (shuffle) {
//播放模式shuffle,1顺序,2单曲,3随机
var that = this;
that.globalData.shuffle = shuffle;
if (shuffle == 1) {
that.globalData.list_am = that.globalData.list_sf;
}
else if (shuffle == 2) {
that.globalData.list_am = [that.globalData.curplay]
}
else {
that.globalData.list_am = [].concat(that.globalData.list_sf);
var sort = that.globalData.list_am;
sort.sort(function () {
return Math.random() - (0.5) ? 1 : -1;
})
}
for (let s in that.globalData.list_am) {
if (that.globalData.list_am[s].id == that.globalData.curplay.id) {
that.globalData.index_am = s;
}
}
},
onShow: function () {
},
onHide: function () {
wx.setStorageSync('globalData', this.globalData);
},
globalData: {
hasLogin: false,
list_am: [],
list_fm: [],
list_sf: [],
index_fm: 0,
index_am: 0,
playtype: 1,
curplay: {},
shuffle: 1,
globalStop: true,
currentPosition: 0
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序仿网易云音乐APP demo完整源码下载
共46个文件
png:39个
jpg:3个
project:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 143 浏览量
2022-02-21
11:36:05
上传
评论
收藏 273KB ZIP 举报
温馨提示
微信小程序仿网易云音乐APP demo完整源码下载
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序仿网易云音乐APP demo完整源码下载.zip (46个子文件)
微信小程序仿网易云音乐APP demo完整源码下载
netmusic-app-master
image
a5p.png 849B
aa1.png 2KB
a_x.png 1KB
a8t.png 2KB
a93.9.png 9KB
a7o.png 341B
cm2_discover_banner_kr-ip6@2x.jpg 58KB
aag.png 17KB
a82.png 13KB
a4k.png 914B
a_k.png 1KB
age.png 5KB
ajb.png 2KB
a_y.png 2KB
a_t.png 1KB
agb.png 3KB
agf.png 2KB
arrow-right.png 1KB
a6l.png 3KB
ajf.png 3KB
a6a.png 197B
a_e.png 2KB
a_i.png 2KB
a_r.png 3KB
aa9.png 3KB
a_p.png 2KB
ajh.png 2KB
aad.png 2KB
a5s.png 1KB
a_f.png 2KB
a5l.png 982B
a4s.png 749B
aah.png 330B
cm2_discover_banner_cn-ip6@2x.jpg 52KB
arrow-left.png 1KB
cm2_discover_banner_jp-ip6@2x.jpg 51KB
a7_.png 649B
a5k.png 2KB
ajd.png 3KB
agg.png 3KB
a5j.png 2KB
aal.png 829B
app.json 1KB
.project 216B
app.wxss 3KB
app.js 4KB
共 46 条
- 1
资源评论
智慧浩海
- 粉丝: 1w+
- 资源: 5170
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功