请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

搜索歌曲时,点击歌手可以正常播放。点击歌曲,获取不了歌曲url,导致不能正常播放

在这里输出歌曲item

selectItem (item) {
 if (item.type === TYPE_SINGER) {
   const singer = new Singer({
     id: item.singermid,
     name: item.singername
   })
   this.$router.push({
     path: `/search/${singer.id}`
   })
   this.setSinger(singer)
 } else {
   console.log(item)
   this.insertSong(item)
 }

https://img1.sycdn.imooc.com//szimg/5c1c9181000156d918290965.jpg

actions代码:也没有发现错误

// 拿到state的原因:最终要拿到playlist currentIndex sequenceList
export const insertSong = function ({commit, state}, song) {
 // state.playlist.slice() 返回state.playlist的一个副本 因为我们不能再mutations回调函数外修改 [vuex] Do not mutate vuex store state outside mutation handlers.
 let playlist = state.playlist.slice()
 let sequenceList = state.sequenceList.slice()
 // currentIndex只是playlist的当前索引 不是sequenceList的索引
 // state.currentIndex 是个值类型 修改变量不会有问题 所以不用副本
 let currentIndex = state.currentIndex
 // 记录当前歌曲
 let currentSong = playlist[currentIndex]
 // 查找当前列表中是否有待插入的歌曲并返回其索引 顺序一定要在插入之前
 let fpIndex = findIndex(playlist, song)
 // 因为是插入歌曲,所以索引+1
 currentIndex++
 // 插入这首歌到当前索引位置
 playlist.splice(currentIndex, 0, song)
 // > -1说明已经有这首歌曲 =-1 没有这首歌曲
 // 如果已经包含了这首歌
 if (fpIndex > -1) {
   if (currentIndex > fpIndex) {
     // 如果当前插入的序号大于列表中的序号
     playlist.splice(fpIndex, 1)
     currentIndex--
   } else {
     // 因为歌在fpIndex之前插入 所以pfIndex增加了一位
     playlist.splice(fpIndex + 1, 1)
   }
 }
 // song 应该插入在sequenceList中的位置
 let currentSIndex = findIndex(sequenceList, currentSong) + 1
 // 寻找之前sequenceList里面有没有我们要插入的song
 let fsIndex = findIndex(sequenceList, song)
 // 插入
 sequenceList.splice(currentSIndex, 0, song)

 if (fsIndex > -1) {
   if (currentSIndex > fsIndex) {
     sequenceList.splice(fsIndex, 1)
   } else {
     sequenceList.splice(fsIndex + 1, 1)
   }
 }
 commit(types.SET_PLAYLIST, playlist)
 commit(types.SET_SEQUENCE_LIST, sequenceList)
 commit(types.SET_CURRENT_INDEX, currentIndex)
 commit(types.SET_FULL_SCREEN, true)
 commit(types.SET_PLAYING_STATE, true)
}

正在回答 回答被采纳积分+3

1回答

提问者 baobaojiayou 2018-12-21 15:42:22

已解决,没有使用processSongsUrl函数

0 回复 有任何疑惑可以回复我~
  • 请问这个函数用在哪里呀,我和你出现了一样的问题
    回复 有任何疑惑可以回复我~ 2019-02-27 16:48:29
  • 提问者 baobaojiayou 回复 慕mio远山 #2
    这个函数是老师课程最后补充的  具体的直接查看老师最终版的源码即可解决
    回复 有任何疑惑可以回复我~ 2019-02-27 19:29:55
  • 慕mio远山 回复 提问者 baobaojiayou #3
    嗯嗯好的谢谢
    回复 有任何疑惑可以回复我~ 2019-02-28 08:39:18
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号