代码拉取完成,页面将自动刷新
<script>
// const iac = uni.createInnerAudioContext()
export default {
onLaunch: function() {
this.iac.src = "http://m8.music.126.net/20210601201227/d693243518c323b90d4a11cffcfa3e89/ymusic/560b/060e/5359/aa1ab79b911dbac1cafcd3ecc539dcb6.mp3";
this.$play();
this.nowSongDown();
},
onShow: function() {
// this.nextSong()
console.log('App Show');
},
onHide: function() {
console.log('App Hide');
},
data(){
return {
song:{
id: 1474342935,
image: 'https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg',
url: "http://m7.music.126.net/20200925213210/db9365f6e7651b24732f1fd45741f14a/ymusic/obj/w5zDlMODwrDDiGjCn8Ky/3788384004/5b1e/2c7e/670b/5f2b70a177ebeb97730048f367a37e83.mp3",
author: '黑猫警长Giao',
title: '画画的baby',
},
nextSong:null,
}
},
components:{
},
computed:{
},
methods:{
// 下一首
// 播放完成监听
nowSongDown() {
this.iac.onEnded(()=>{
let nowListIndex = this.$store.getters.nextPlayData.nowListIndex;
let nowSongIndex = this.$store.getters.nextPlayData.nowSongIndex;
let nowList = this.$store.getters.listData[nowListIndex].lists;
nowSongIndex = nowSongIndex < nowList.length-1 ? nowSongIndex+1:0;
uni.request({
url: "http://119.3.174.206:3000/song/url?id=" + nowList[nowSongIndex].id,
success: (res) => {
console.log(res.data)
if(!res.data.data[0].url)return console.log('这歌要钱')
this.iac.src = res.data.data[0].url
this.$store.commit('nowPlayChange', {playState:true});
this.$store.commit('songChange', {
...nowList[nowSongIndex],
url: res.data.data[0].url
})
this.iac.play()
}
})
console.log('nowList',nowList[nowSongIndex])
this.$store.commit('nowSongChange', {nowSongIndex: nowSongIndex, nowListIndex: nowListIndex})
})
},
// 当前播放器时间
nowSongTime() {
return {
currentTime: iac.currentTime,
allTime: iac.duration,
buffered: iac.buffered//缓冲位
}
},
// 下一首
nextSong(that){
console.log(1);
console.log(this)
},
//播放
playSong(){
iac.play();
},
// 暂停
stopSong() {
iac.pause();
},
// 上一首
lastSong() {
}
}
};
</script>
<style>
@import url("http://at.alicdn.com/t/font_2064057_z1hq0qe6n3r.css");
/*每个页面公共css */
.uni-tabbar .uni-tabbar__icon.uni-tabbar__icon__diff {
transition: all linear 1s;
animation: xuanZhan 3s linear infinite;
}
uni-icon>i:before {
margin: 0;
box-sizing: border-box;
position: absolute;
right: 58rpx;
top: 30rpx;
cursor: pointer;
}
uni-swiper .uni-swiper-slides {
margin: 0 22rpx;
overflow: hidden;
border-radius: 10px;
}
@keyframes xuanZhan{
0{}
100%{
transform: rotate(360deg);
}
}
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。