Skip to content

Commit d801879

Browse files
committed
fix(avplayer): 自动播放音频时如果 audioContext 处于 suspended 状态不抛错误,修改成触发 RESUME 事件
1 parent c087a62 commit d801879

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/avplayer/AVPlayer.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -2043,15 +2043,12 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
20432043
this.video?.play(),
20442044
this.audio?.play()
20452045
]).catch((error) => {
2046+
this.fire(eventType.RESUME)
2047+
logger.warn('the audioContext was not started. It must be resumed after a user gesture')
20462048
if (this.video) {
20472049
this.video.muted = true
2048-
this.fire(eventType.RESUME)
2049-
logger.warn('the audioContext was not started. It must be resumed after a user gesture')
20502050
return this.video.play()
20512051
}
2052-
else {
2053-
throw error
2054-
}
20552052
})
20562053
}
20572054
else {
@@ -2075,10 +2072,6 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
20752072
await AVPlayer.AudioRenderThread.fakePlay(this.taskId)
20762073
this.controller.setTimeUpdateListenType(AVMediaType.AVMEDIA_TYPE_VIDEO)
20772074
}
2078-
else {
2079-
// 只有音频无法播放时直接抛错,和 mse 行为保持一致
2080-
throw new Error('the audioContext was not started. It must be resumed after a user gesture')
2081-
}
20822075
}
20832076
}
20842077
this.status = AVPlayerStatus.PLAYED
@@ -2578,21 +2571,18 @@ export default class AVPlayer extends Emitter implements ControllerObserver {
25782571
if (this.audioSourceNode) {
25792572
this.controller.setTimeUpdateListenType(AVMediaType.AVMEDIA_TYPE_AUDIO)
25802573
}
2581-
if (this.video) {
2582-
this.video.muted = false
2583-
}
25842574
this.fire(eventType.AUDIO_CONTEXT_RUNNING)
25852575
}
25862576
}
25872577
if (this.video) {
25882578
this.video.muted = false
2589-
if (!this.video.played) {
2579+
if (this.video.paused) {
25902580
await this.video.play()
25912581
}
25922582
}
25932583
else if (this.audio) {
25942584
this.audio.muted = false
2595-
if (!this.audio.played) {
2585+
if (this.audio.paused) {
25962586
await this.audio.play()
25972587
}
25982588
}

0 commit comments

Comments
 (0)