Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当歌词为空时会有报错 #283

Open
yodagg opened this issue Aug 6, 2019 · 6 comments
Open

当歌词为空时会有报错 #283

yodagg opened this issue Aug 6, 2019 · 6 comments

Comments

@yodagg
Copy link
Contributor

yodagg commented Aug 6, 2019

描述

第一首歌播放的过程中切换到第二首歌(第二首歌无歌词),将会报错。

资源

[
    {
        name: '星星点灯',    // 本地资源
        artist: '郑智化',
        url: './xx.m4a',
        cover: './xx.jpg',
        lrc: './xx.lrc'
    },
    {
        name: '天空之城',    // 线上资源
        artist: '久石让',
        url: 'http://xx.mp3',
        cover: '',
        lrc: ''
    }
]

报错

Uncaught TypeError: Cannot read property 'classList' of undefined
20190806112103

版本

1.10.1

@yodagg
Copy link
Contributor Author

yodagg commented Aug 6, 2019

触发逻辑有点奇怪,偶尔会出现,都用线上资源好像就不会触发。

大概的规律

第一首歌是本地资源,第二首歌是线上资源

  1. 先播放第一首歌,然后进度条往右拉一段
  2. 切第二首歌,进度条往右拉一段
  3. 切回第一首,同样拉一段进度条
  4. 这时候就会出现报错了

@Copay
Copy link

Copay commented Aug 6, 2019

@so-diao 能否给一个复现demo?codepen和jsbin抑或是jsfiddle都行

@yodagg
Copy link
Contributor Author

yodagg commented Aug 6, 2019

@so-diao 能否给一个复现demo?codepen和jsbin抑或是jsfiddle都行

@Copay https://codepen.io/anon/pen/vopZVo
资源需要本地的,用线上的没发现有报错

@yansheng836
Copy link

对于有些歌曲没有歌词的情况,不建议直接置为空lrc: '',,这样会出现问题:一开始可能没有问题,如果设置循环,第二次时就会报错–找不到歌词。建议:添加同名歌词文件,如久石让-天空之城.lrc,歌词内容置为空,如:[00:00.00] 暂无歌词,这样就不会出现类似问题。

@yodagg
Copy link
Contributor Author

yodagg commented Feb 24, 2020

对于有些歌曲没有歌词的情况,不建议直接置为空lrc: '',,这样会出现问题:一开始可能没有问题,如果设置循环,第二次时就会报错–找不到歌词。建议:添加同名歌词文件,如久石让-天空之城.lrc,歌词内容置为空,如:[00:00.00] 暂无歌词,这样就不会出现类似问题。

是一个解决办法,这一步让插件做比较合适。

@liuly0322
Copy link

liuly0322 commented Mar 4, 2024

由于看起来这个包不再更新了,虽然 #284 被合并但是无法使用,下面是一个解决这个问题的 monkey patch:

instance = new APlayer({
  // ......
})

const _switch = instance.lrc.switch
const _update = instance.lrc.update
instance.lrc.switch = (index) => {
  instance.lrc.update = () => {}
  _switch.call(instance.lrc, index)
  instance.lrc.update = _update
}

原理:

// list.js
this.player.lrc && this.player.lrc.switch(this.index);
this.player.lrc && this.player.lrc.update(0);
// lrc 定义在 lrc.js 中,只有这一处调用

this.player.lrc.switch(this.index) 内并不需要调用 update

liuly0322 added a commit to liuly0322/aplayer-ts that referenced this issue Mar 4, 2024
liuly0322 added a commit to liuly0322/Q-Blog that referenced this issue Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants