const bgMusic = wx.createInnerAudioContext()
const app = getApp()
var audioAnimation;
Page({
data: {
index: '0',
title_list: [{
name: '依诺',
time: '',
title: '爱如禅翼',
src: 'http://yc42.data.mvbox.cn/music/fc/16/12/22/16122209085334272091.mp3',
id: 0,
img: '/pages/images/yinuo.jpg',
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/02/17010212305303052571.mp3',
title: '黄昏来临',
img: '/pages/images/yinuo1.jpg',
id: 1
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/02/17010212295008834192.mp3',
title: '红颜旧',
img: '/pages/images/yinuo.jpg',
id: 2
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/02/17010212314380966252.mp3',
title: '剪爱',
img: '/pages/images/yinuo1.jpg',
id: 3
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/02/17010212321551078776.mp3',
title: '空',
img: '/pages/images/yinuo.jpg',
id: 4
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/02/17010212332559141885.mp3',
title: '那一夜',
img: '/pages/images/yinuo1.jpg',
id: 5
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010312271585223317.mp3',
title: '难道',
img: '/pages/images/yinuo.jpg',
id: 6
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316401496232532.mp3',
title: '请你等等我',
img: '/pages/images/yinuo1.jpg',
id: 7
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316405832026195.mp3',
title: '雪人',
img: '/pages/images/yinuo.jpg',
id: 8
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316415540710515.mp3',
title: '因为爱上你',
img: '/pages/images/yinuo1.jpg',
id: 9
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316432073528278.mp3',
title: '勇气',
img: '/pages/images/yinuo.jpg',
id: 10
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316440895336504.mp3',
title: '约定',
img: '/pages/images/yinuo1.jpg',
id: 11
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316445321215516.mp3',
title: '再不疯狂我们就老了',
img: '/pages/images/yinuo.jpg',
id: 12
}, {
name: '依诺',
time: '',
src: 'http://data.mvbox.cn/music/fc/17/01/03/17010316454657585137.mp3',
title: '重庆野玫瑰',
img: '/pages/images/yinuo1.jpg',
id: 13
}
],
heighTrue: true,
showModalStatus: false,
show: 'none',
isOpen: true,
starttime: '00:00',
duration: '00:00',
music_on: true,
music_playing: true,
},
onLoad: function () {
var that = this
that.s_p()
},
play_shang: function () {
var that = this
var id = parseInt(this.data.index)
var num = id - 1
if (id - 1 < 0) {
wx.showToast({
title: '已是第一个',
})
} else {
this.setData({
music_on: false,
index: num,
'color': '#0b68f3',
'clickId': num,
src: '',
duration: '',
})
that.s_p()
}
},
play_xia: function () {
var that = this
var id = parseInt(this.data.index)
var num = id + 1
if (id + 1 > this.data.title_list.length - 1) {
wx.showToast({
title: '已是最后一个',
})
} else {
this.setData({
music_on: false,
index: num,
'color': '#0b68f3',
'clickId': num,
src: '',
duration: '',
})
that.s_p()
}
},
s_p: function () {
var that = this
var src = this.data.title_list[this.data.index].src
var img = this.data.title_list[this.data.index].img
var title = this.data.title_list[this.data.index].title
this.setData({
'color': '#0b68f3',
'clickId': this.data.index,
src: src,
img: img,
title: title
})
that.listenerButtonPlay()
},
play_list: function (e) {
var that = this
var id = e.target.id
that.setData({
'color': '#0b68f3',
'clickId': id,
index: id,
display_rue: 'block',
});
if (this.data.src == '') {
that.s_p()
that.setData({
'color': '#0b68f3',
'clickId': id,
index: id,
display_rue: 'block',
});
} else {
that.listenerButtonPlay()
that.setData({
'color': '#0b68f3',
'clickId': id,
index: id,
display_rue: 'block',
src: ''
});
}
},
showModal: function () {
var that = this
this.setData({
show: 'block'
})
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
showModalStatus: true,
heighTrue: false,
ball_height: 1,
show: 'block'
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export()
})
}.bind(this), 200)
},
hide: function () {
var animation = wx.createAnimation({
duration: 200,
timingFunction: "linear",
delay: 0
})
this.animation = animation
animation.translateY(300).step()
this.setData({
animationData: animation.export(),
})
setTimeout(function () {
animation.translateY(0).step()
this.setData({
animationData: animation.export(),
showModalStatus: false,
heighTrue: true,
ball_height: 2,
show: 'none',
})
}.bind(this), 200)
},
listenerButtonPlay: function (e) {
var that = this
var sec = this.data.src
bgMusic.title = '此时此刻'
bgMusic.epname = '此时此刻'
bgMusic.src = that.data.src;
this.data.music_on = true;
this.data.music_playing = true;
bgMusic.play();
this.setData({
music_on: true,
music_playing: this.data.music_playing,
})
bgMusic.onTimeUpdate(() => {
var duration = bgMusic.duration;
var offset = bgMusic.currentTime;
var currentTime = parseInt(bgMusic.currentTime);
var min = "0" + parseInt(currentTime / 60);
var max = parseInt(bgMusic.duration);
var sec = currentTime % 60;
var maxtime = max / 60
var max_time = parseInt(maxtime);
var x_maxtime = maxtime - max_time;
var yu_time = parseInt(x_maxtime * 60)
if (sec < 10) {
sec = "0" + sec;
};
var starttime = min + ':' + sec;
var time_time = max_time + ':' + yu_time
that.setData({
isOpen: true,
duration: time_time,
offset: currentTime,
starttime: starttime,
max: max,
changePlay: true,
})
})
bgMusic.onError((res) => {
that.prompt.message('网络出错,稍后再试')
})
bgMusic.onEnded((res) => {
var that = this
var id = parseInt(this.data.index)
var num = id + 1
if (id + 1 > this.data.title_list.length - 1) {
wx.showToast({
title: '已是最后一个',
})
} else {
this.setData({
music_on: false,
index: num,
'color': '#0b68f3',
'clickId': num,
src: '',
duration: '',
})
that.s_p()
}
})
},
listenerButtonPause() {
this.data.music_on = true;
this.data.music_playing = false;
var that = this
bgMusic.pause()
that.setData({
isOpen: false,
music_on: this.data.music_on,
music_playing: this.data.music_playing,
})
},
sliderChange(e) {
var that = this
var offset = parseInt(e.detail.value);
bgMusic.play();
bgMusic.seek(offset);
that.setData({
isOpen: true,
})
},
onShareAppMessage: function (res) {
if (res.from === 'button') {
console.log(res.target)
}
return {
title: '太好听了,一直听到天亮!',
path: 'pages/yinuo/yinuo?id=123',
success: function (res) {
console.log('分享成功')
},
fail: function (res) {
console.log('分享失败')
}
}
},
onUnload: function () {
bgMusic.stop();
}
})
为什么每次分享时,不管播放那一首歌,都是分享页面的第一首歌《爱如禅翼》的?
分享id 通过id去取指定歌曲的数据
谢谢同志们,弄好了,但又有一个问题出现了,就是播放页面弹出一个很小的白色播放窗口,是不是微信自带的吗?怎去掉?
你在pages/yinuo/yinuo这个页面获取到id了吗??做处理了吗