@aochuang/common 1.0.143 → 1.0.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/voice/voice-player-aac.js +15 -15
- package/package.json +1 -1
|
@@ -65,7 +65,7 @@ export default class VoicePlayerAAC {
|
|
|
65
65
|
this._timer = setInterval(() => {
|
|
66
66
|
if (!this._play) return
|
|
67
67
|
const currPosition = this.$audio.currentTime
|
|
68
|
-
this.options.onPlaying
|
|
68
|
+
this.options.onPlaying && this.options.onPlaying({
|
|
69
69
|
currPosition,
|
|
70
70
|
totalPosition
|
|
71
71
|
})
|
|
@@ -76,7 +76,7 @@ export default class VoicePlayerAAC {
|
|
|
76
76
|
}, 100)
|
|
77
77
|
}
|
|
78
78
|
this.$audio.onplay = () => {
|
|
79
|
-
this.options.onPlay
|
|
79
|
+
this.options.onPlay && this.options.onPlay()
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
this.$audio.onended = () => {
|
|
@@ -91,11 +91,11 @@ export default class VoicePlayerAAC {
|
|
|
91
91
|
|
|
92
92
|
this.$audio.addEventListener('stop', () => {
|
|
93
93
|
clearInterval(this._timer)
|
|
94
|
-
this.options.onEnded
|
|
94
|
+
this.options.onEnded && this.options.onEnded()
|
|
95
95
|
})
|
|
96
96
|
|
|
97
97
|
this.$audio.addEventListener('error', () => {
|
|
98
|
-
this.options.onError
|
|
98
|
+
this.options.onError && this.options.onError({
|
|
99
99
|
type: 'aac',
|
|
100
100
|
url: this._url,
|
|
101
101
|
message: this.$audio.error || '未知音频错误'
|
|
@@ -146,7 +146,7 @@ export default class VoicePlayerAAC {
|
|
|
146
146
|
if (!url) {
|
|
147
147
|
this.stop()
|
|
148
148
|
}
|
|
149
|
-
cb
|
|
149
|
+
cb && cb({ status: 'success' })
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
start() {
|
|
@@ -193,7 +193,7 @@ export default class VoicePlayerAAC {
|
|
|
193
193
|
this.$audio.addEventListener('playing', () => this.isPlaying = true)
|
|
194
194
|
this.$audio.addEventListener('pause', () => this.isPlaying = false)
|
|
195
195
|
this.mediaSource.addEventListener('sourceerror', (e) => {
|
|
196
|
-
this.options.onError
|
|
196
|
+
this.options.onError && this.options.onError({ type: 'mse', url: this._url, message: e })
|
|
197
197
|
})
|
|
198
198
|
this.mediaSource.addEventListener('sourceopen', async () => {
|
|
199
199
|
if (!this._play) return
|
|
@@ -230,7 +230,7 @@ export default class VoicePlayerAAC {
|
|
|
230
230
|
if (bufferStart < cleanEnd && cleanEnd <= bufferEnd) {
|
|
231
231
|
try {
|
|
232
232
|
await this.safeRemoveBuffer(this.sourceBuffer, bufferStart, cleanEnd)
|
|
233
|
-
} catch {
|
|
233
|
+
} catch (e) {
|
|
234
234
|
// 清理失败时跳过本次清理,后续追加失败会走 appendBufferSafe 的配额兜底。
|
|
235
235
|
}
|
|
236
236
|
}
|
|
@@ -246,7 +246,7 @@ export default class VoicePlayerAAC {
|
|
|
246
246
|
this.mediaSource.endOfStream()
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
} catch {
|
|
249
|
+
} catch (e) {
|
|
250
250
|
// 当前分片加载失败时停止本轮追加,下一轮缓冲检查会继续尝试。
|
|
251
251
|
} finally {
|
|
252
252
|
this.loadNextSegment = false
|
|
@@ -262,7 +262,7 @@ export default class VoicePlayerAAC {
|
|
|
262
262
|
}, 500)
|
|
263
263
|
|
|
264
264
|
} catch (e) {
|
|
265
|
-
this.options.onError
|
|
265
|
+
this.options.onError && this.options.onError({ type: 'mse', url: this._url, message: e })
|
|
266
266
|
}
|
|
267
267
|
}, { once: true })
|
|
268
268
|
this.$audio.play().catch(() => {})
|
|
@@ -297,7 +297,7 @@ export default class VoicePlayerAAC {
|
|
|
297
297
|
})
|
|
298
298
|
}
|
|
299
299
|
} catch (err) {
|
|
300
|
-
this.options.onError
|
|
300
|
+
this.options.onError && this.options.onError({ type: 'global', url: this._url, message: err })
|
|
301
301
|
}
|
|
302
302
|
}).finally(() => {
|
|
303
303
|
this.downloading = false
|
|
@@ -321,7 +321,7 @@ export default class VoicePlayerAAC {
|
|
|
321
321
|
// 兜底:强制清空所有缓冲
|
|
322
322
|
try {
|
|
323
323
|
sourceBuffer.remove(0, sourceBuffer.buffered.end(0))
|
|
324
|
-
} catch {}
|
|
324
|
+
} catch (e) {}
|
|
325
325
|
return false
|
|
326
326
|
}
|
|
327
327
|
}
|
|
@@ -379,7 +379,7 @@ export default class VoicePlayerAAC {
|
|
|
379
379
|
}
|
|
380
380
|
const [start, end] = this.getBufferedRange()
|
|
381
381
|
return [start, end]
|
|
382
|
-
} catch {
|
|
382
|
+
} catch (e) {
|
|
383
383
|
return [0, 0]
|
|
384
384
|
} finally {
|
|
385
385
|
this.isPreloading = false
|
|
@@ -426,7 +426,7 @@ export default class VoicePlayerAAC {
|
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
} catch (err) {
|
|
429
|
-
this.options.onError
|
|
429
|
+
this.options.onError && this.options.onError({ type: 'mse', url: this._url, message: err })
|
|
430
430
|
} finally {
|
|
431
431
|
// 延迟释放锁,确保缓冲完全加载
|
|
432
432
|
setTimeout(() => {
|
|
@@ -529,14 +529,14 @@ export default class VoicePlayerAAC {
|
|
|
529
529
|
|
|
530
530
|
stop (callback) {
|
|
531
531
|
if (!this._play) {
|
|
532
|
-
callback
|
|
532
|
+
callback && callback()
|
|
533
533
|
return
|
|
534
534
|
}
|
|
535
535
|
this._play = false
|
|
536
536
|
this.$audio.pause()
|
|
537
537
|
this.$audio.currentTime = 0
|
|
538
538
|
this.$audio.dispatchEvent(new Event('stop'))
|
|
539
|
-
callback
|
|
539
|
+
callback && callback()
|
|
540
540
|
}
|
|
541
541
|
|
|
542
542
|
destroy() {
|