Skip to content

Commit a94e505

Browse files
authored
Merge pull request #991 from ITManCHINA/web-audio-optimization
🐞 fix: 修复延迟补偿在playback模式意外丢失补偿值的逻辑bug
2 parents 9f61526 + 896fcfa commit a94e505

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/core/audio-player/AudioElementPlayer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type AudioEventType,
66
} from "./BaseAudioPlayer";
77
import type { EngineCapabilities } from "./IPlaybackEngine";
8+
import { useSettingStore } from "@/stores";
89

910
/**
1011
* 基于 HTMLAudioElement 的播放器实现
@@ -196,11 +197,21 @@ export class AudioElementPlayer extends BaseAudioPlayer {
196197
if (this.isInternalSeeking) {
197198
return this.targetSeekTime;
198199
}
200+
const settingStore = useSettingStore();
201+
202+
const isPlayback = settingStore.audioLatencyHint === "playback";
203+
204+
let autoLatency = 0;
205+
206+
if (isPlayback && this.audioCtx) {
207+
autoLatency = (this.audioCtx.outputLatency || 0) + (this.audioCtx.baseLatency || 0);
208+
}
209+
const manualCompensation = isPlayback ? this.audioDelayCompensation / 1000 : 0;
199210
// 基础时间 - 自动延迟补偿 + 手动延迟补偿
200211
return (
201212
(this.audioElement.currentTime || 0) -
202-
this.compensatedLatency +
203-
this.audioDelayCompensation / 1000
213+
autoLatency +
214+
manualCompensation
204215
);
205216
}
206217

0 commit comments

Comments
 (0)