@@ -43,6 +43,7 @@ import Lyric from 'lrc-file-parser'
4343import { rendererSend } from ' ../../../common/icp'
4444import { formatPlayTime2 , getRandom , checkPath } from ' ../../utils'
4545import { mapGetters , mapActions , mapMutations } from ' vuex'
46+ import { requestMsg } from ' ../../utils/message'
4647
4748export default {
4849 data () {
@@ -68,7 +69,8 @@ export default {
6869 text: ' ' ,
6970 line: 0 ,
7071 },
71- retryNum: 0 ,
72+ delayNextTimeout: null ,
73+ // retryNum: 0,
7274 }
7375 },
7476 computed: {
@@ -119,8 +121,13 @@ export default {
119121 ? n .findIndex (s => s .musicInfo .songmid === this .musicInfo .songmid )
120122 : n .findIndex (s => s .songmid === this .musicInfo .songmid )
121123 if (index < 0 ) {
122- this .fixPlayIndex (this .playIndex - 1 )
123- if (n .length ) this .handleNext ()
124+ // console.log(this.playIndex)
125+ if (n .length ) {
126+ this .fixPlayIndex (this .playIndex - 1 )
127+ this .handleNext ()
128+ } else {
129+ this .setPlayIndex (- 1 )
130+ }
124131 } else {
125132 this .fixPlayIndex (index)
126133 }
@@ -167,7 +174,7 @@ export default {
167174 // console.log('code', this.audio.error.code)
168175 if (! this .musicInfo .songmid ) return
169176 console .log (' 出错' )
170- if (this .audio .error .code == 4 && this .retryNum < 5 ) {
177+ if (this .audio .error .code == 4 && this .retryNum < 3 ) { // 若音频URL无效则尝试刷新3次URL
171178 // console.log(this.retryNum)
172179 this .retryNum ++
173180 this .setUrl (this .list [this .playIndex ], true )
@@ -191,10 +198,8 @@ export default {
191198 // } else {
192199 // this.handleNext()
193200 // }
194- this .status = ' 音频加载出错,2 两秒后切换下一首'
195- setTimeout (() => {
196- this .handleNext ()
197- }, 2000 )
201+ this .status = ' 音频加载出错,5 秒后切换下一首'
202+ this .addDelayNextTimeout ()
198203 })
199204 this .audio .addEventListener (' loadeddata' , () => {
200205 this .maxPlayTime = this .audio .duration
@@ -241,6 +246,7 @@ export default {
241246 },
242247 play () {
243248 console .log (' play' , this .playIndex )
249+ this .checkDelayNextTimeout ()
244250 let targetSong = this .targetSong = this .list [this .playIndex ]
245251 this .retryNum = 0
246252
@@ -264,6 +270,20 @@ export default {
264270 this .setLrc (targetSong)
265271 }
266272 },
273+ checkDelayNextTimeout () {
274+ console .log (this .delayNextTimeout )
275+ if (this .delayNextTimeout ) {
276+ clearTimeout (this .delayNextTimeout )
277+ this .delayNextTimeout = null
278+ }
279+ },
280+ addDelayNextTimeout () {
281+ this .checkDelayNextTimeout ()
282+ this .delayNextTimeout = setTimeout (() => {
283+ this .delayNextTimeout = null
284+ this .handleNext ()
285+ }, 5000 )
286+ },
267287 handleNext () {
268288 // if (this.list.listName === null) return
269289 let list
@@ -276,7 +296,7 @@ export default {
276296 }
277297 if (! list .length ) return this .setPlayIndex (- 1 )
278298 let playIndex = this .list === list ? this .playIndex : list .indexOf (this .list [this .playIndex ])
279-
299+ console . log (playIndex)
280300 let index
281301 switch (this .setting .player .togglePlayMethod ) {
282302 case ' listLoop' :
@@ -349,19 +369,12 @@ export default {
349369 this .musicInfo .url = targetSong .typeUrl [type]
350370 this .status = ' 歌曲链接获取中...'
351371
352- let urlP = this .musicInfo .url && ! isRefresh
353- ? Promise .resolve ()
354- : this .getUrl ({ musicInfo: targetSong, type }).then (() => {
355- this .musicInfo .url = targetSong .typeUrl [type]
356- })
357-
358- urlP .then (() => {
359- this .audio .src = this .musicInfo .url
372+ this .getUrl ({ musicInfo: targetSong, type, isRefresh }).then (() => {
373+ this .audio .src = this .musicInfo .url = targetSong .typeUrl [type]
360374 }).catch (err => {
375+ if (err .message == requestMsg .cancelRequest ) return
361376 this .status = err .message
362- setTimeout (() => {
363- this .handleNext ()
364- }, 2000 )
377+ this .addDelayNextTimeout ()
365378 })
366379 },
367380 setImg (targetSong ) {
0 commit comments