@@ -61,12 +61,14 @@ export default {
6161 name: ' ^' ,
6262 singer: ' ^' ,
6363 },
64+ targetSong: null ,
6465 pregessWidth: 0 ,
6566 lyric: {
6667 lrc: null ,
6768 text: ' ' ,
6869 line: 0 ,
6970 },
71+ retryNum: 0 ,
7072 }
7173 },
7274 computed: {
@@ -137,6 +139,7 @@ export default {
137139 ' fixPlayIndex' ,
138140 ' resetChangePlay' ,
139141 ]),
142+ ... mapMutations (' list' , [' updateMusicInfo' ]),
140143 init () {
141144 this .audio = document .createElement (' audio' )
142145 this .audio .controls = false
@@ -161,10 +164,16 @@ export default {
161164 this .handleNext ()
162165 })
163166 this .audio .addEventListener (' error' , () => {
167+ // console.log('code', this.audio.error.code)
164168 if (! this .musicInfo .songmid ) return
165169 console .log (' 出错' )
170+ if (this .audio .error .code == 4 && this .retryNum < 5 ) {
171+ // console.log(this.retryNum)
172+ this .retryNum ++
173+ this .setUrl (this .list [this .playIndex ], true )
174+ return
175+ }
166176 this .stopPlay ()
167- this .status = ' 加载出错'
168177 this .sendProgressEvent (this .progress , ' error' )
169178
170179 // let urls = this.player_info.targetSong.urls
@@ -182,10 +191,14 @@ export default {
182191 // } else {
183192 // this.handleNext()
184193 // }
185- this .handleNext ()
194+ this .status = ' 音频加载出错,2 两秒后切换下一首'
195+ setTimeout (() => {
196+ this .handleNext ()
197+ }, 2000 )
186198 })
187199 this .audio .addEventListener (' loadeddata' , () => {
188200 this .maxPlayTime = this .audio .duration
201+ if (! this .targetSong .interval && this .listId != ' download' ) this .updateMusicInfo ({ index: this .playIndex , data: { interval: formatPlayTime2 (this .maxPlayTime ) } })
189202 this .status = ' 音乐加载中...'
190203 })
191204 // this.audio.addEventListener('loadstart', () => {
@@ -228,7 +241,8 @@ export default {
228241 },
229242 play () {
230243 console .log (' play' , this .playIndex )
231- let targetSong = this .list [this .playIndex ]
244+ let targetSong = this .targetSong = this .list [this .playIndex ]
245+ this .retryNum = 0
232246
233247 if (this .listId == ' download' ) {
234248 if (! checkPath (targetSong .filePath ) || ! targetSong .isComplate || / \. ape$ / .test (targetSong .filePath )) {
@@ -321,16 +335,21 @@ export default {
321335 this .musicInfo .img = null
322336 },
323337 getPlayType (highQuality , songInfo ) {
338+ switch (songInfo .source ) {
339+ case ' wy' :
340+ case ' kg' :
341+ return ' 128k'
342+ }
324343 let type = songInfo ._types [' 192k' ] ? ' 192k' : ' 128k'
325344 if (highQuality && songInfo ._types [' 320k' ]) type = ' 320k'
326345 return type
327346 },
328- setUrl (targetSong ) {
347+ setUrl (targetSong , isRefresh ) {
329348 let type = this .getPlayType (this .setting .player .highQuality , targetSong)
330349 this .musicInfo .url = targetSong .typeUrl [type]
331350 this .status = ' 歌曲链接获取中...'
332351
333- let urlP = this .musicInfo .url
352+ let urlP = this .musicInfo .url && ! isRefresh
334353 ? Promise .resolve ()
335354 : this .getUrl ({ musicInfo: targetSong, type }).then (() => {
336355 this .musicInfo .url = targetSong .typeUrl [type]
@@ -366,7 +385,7 @@ export default {
366385 lrcP
367386 .then (() => {
368387 this .lyric .lrc .setLyric (this .musicInfo .lrc )
369- if (this .isPlay ) this .lyric .lrc .play (this .audio .currentTime * 1000 )
388+ if (this .isPlay && ( this . musicInfo . url || this . listId == ' download ' ) ) this .lyric .lrc .play (this .audio .currentTime * 1000 )
370389 })
371390 .catch (err => {
372391 this .status = err .message
0 commit comments