From 68ecaf8357ffd82975bc0256601824ff69d04c21 Mon Sep 17 00:00:00 2001 From: zhaohappy <2281756061@qq.com> Date: Sun, 9 Feb 2025 19:34:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(avplayer):=20=E8=87=AA=E5=8A=A8=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E9=9F=B3=E9=A2=91=E6=97=B6=E5=A6=82=E6=9E=9C=20audioC?= =?UTF-8?q?ontext=20=E5=A4=84=E4=BA=8E=20suspended=20=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8D=E6=8A=9B=E5=87=BA=EF=BC=8C=E6=8A=9B=E5=87=BA=20RESUME?= =?UTF-8?q?=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/avplayer/AVPlayer.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/avplayer/AVPlayer.ts b/src/avplayer/AVPlayer.ts index fb4321bf..075f8995 100644 --- a/src/avplayer/AVPlayer.ts +++ b/src/avplayer/AVPlayer.ts @@ -2043,15 +2043,12 @@ export default class AVPlayer extends Emitter implements ControllerObserver { this.video?.play(), this.audio?.play() ]).catch((error) => { + this.fire(eventType.RESUME) + logger.warn('the audioContext was not started. It must be resumed after a user gesture') if (this.video) { this.video.muted = true - this.fire(eventType.RESUME) - logger.warn('the audioContext was not started. It must be resumed after a user gesture') return this.video.play() } - else { - throw error - } }) } else { @@ -2075,10 +2072,6 @@ export default class AVPlayer extends Emitter implements ControllerObserver { await AVPlayer.AudioRenderThread.fakePlay(this.taskId) this.controller.setTimeUpdateListenType(AVMediaType.AVMEDIA_TYPE_VIDEO) } - else { - // 只有音频无法播放时直接抛错,和 mse 行为保持一致 - throw new Error('the audioContext was not started. It must be resumed after a user gesture') - } } } this.status = AVPlayerStatus.PLAYED @@ -2578,21 +2571,18 @@ export default class AVPlayer extends Emitter implements ControllerObserver { if (this.audioSourceNode) { this.controller.setTimeUpdateListenType(AVMediaType.AVMEDIA_TYPE_AUDIO) } - if (this.video) { - this.video.muted = false - } this.fire(eventType.AUDIO_CONTEXT_RUNNING) } } if (this.video) { this.video.muted = false - if (!this.video.played) { + if (this.video.paused) { await this.video.play() } } else if (this.audio) { this.audio.muted = false - if (!this.audio.played) { + if (this.audio.paused) { await this.audio.play() } }