0%

cc-audiobuffer2

cc-audiobuffer 2.x 版本

Gayhub 源码与2.x文章 喜欢给个Star !

不断完善更新中

1.x版本文章: 文章

更新功能

  • 当前播放语音暂停
  • 当前播放语音继续播放
  • 清空当前的语音队列

使用请看 源码Markdown

源码的升级

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
_playNext() {
const _this = this
if (this._isHasBuffer() && !this._isHasCurrentAudio()) {
this.currentAudio = this._shiftBuffer()
this.currentAudio.play()
} else if (!this._isHasBuffer()) {
this.currentAudio = null
}
if (this._isHasCurrentAudio()) {
this.currentAudio.addEventListener('ended', function() {
_this.currentAudio = null
_this._playNext()
}, false)
}
}

解释

_playNext() 函数无论在一开始播放和暂停之后继续播放都要调用。

如何区分当前时一开始播放还是暂停后的继续播放呢?

利用this._isHasCurrentAudio 判断当前是否有载入语音,如果有就是暂停后继续播放,反之就是一开始的初始播放。

接下来即将要实现的功能

  • 接下来的计划:单例模式、报错处理、暂停播放继续播放清空队列优化