web: Fix hangs on Safari by avoiding getOutputTimestamp
`AudioContext.getOutputTimestamp` returns incorrect values in Safari 15.1+, and this would cause movies with 'stream' sounds to soft-lock because the calculated audio position would barely progress. See: https://developer.apple.com/forums/thread/696356 Change the output timestamp calculation to use `AudioContext.currentTime` instead.
This commit is contained in:
parent
fa70cc07ab
commit
dd45dc81a0
|
@ -28,13 +28,12 @@ export function copyToAudioBuffer(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `AudioContext.getOutputTimestamp`, defaulting to `context.currentTime` if
|
* Returns the estimated output timestamp for the audio context.
|
||||||
* `getOutputTimestamp` is unavailable. This is necessary because `web-sys` does not yet export
|
* This is necessary because web-sys does not export `AudioContext.baseLatency`.
|
||||||
* `AudioBuffer.copyToChannel`.
|
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export function getAudioOutputTimestamp(context: AudioContext): number {
|
export function getAudioOutputTimestamp(context: AudioContext): number {
|
||||||
const timestamp = context.getOutputTimestamp?.();
|
// TODO: Ideally we'd use `context.getOutputTimestamp`, but this is broken as of Safari 15.4.
|
||||||
return timestamp?.contextTime ?? context.currentTime - context.baseLatency;
|
return context.currentTime - context.baseLatency;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue