1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-15 13:51:40 +00:00

Merge pull request #109790 from adamscott/tentative-fix-for-109144

[Web] Fix `AudioStreamPlayer.get_playback_position()` returning incorrect values for samples
This commit is contained in:
Thaddeus Crews
2025-08-25 09:54:18 -05:00
2 changed files with 23 additions and 12 deletions

View File

@@ -29,22 +29,28 @@
/**************************************************************************/ /**************************************************************************/
class GodotPositionReportingProcessor extends AudioWorkletProcessor { class GodotPositionReportingProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() {
return [
{
name: 'reset',
defaultValue: 0,
minValue: 0,
maxValue: 1,
automationRate: 'k-rate',
},
];
}
constructor(...args) { constructor(...args) {
super(...args); super(...args);
this.position = 0; this.position = 0;
this.port.onmessage = (event) => {
switch (event?.data?.type) {
case 'reset':
this.position = 0;
break;
default:
// Do nothing.
}
};
} }
process(inputs, _outputs, _parameters) { process(inputs, _outputs, parameters) {
if (parameters['reset'][0] > 0) {
this.position = 0;
}
if (inputs.length > 0) { if (inputs.length > 0) {
const input = inputs[0]; const input = inputs[0];
if (input.length > 0) { if (input.length > 0) {

View File

@@ -643,6 +643,7 @@ class SampleNode {
'godot-position-reporting-processor' 'godot-position-reporting-processor'
); );
} }
this._playbackPosition = this.offset;
this._positionWorklet.port.onmessage = (event) => { this._positionWorklet.port.onmessage = (event) => {
switch (event.data['type']) { switch (event.data['type']) {
case 'position': case 'position':
@@ -652,7 +653,11 @@ class SampleNode {
// Do nothing. // Do nothing.
} }
}; };
this._positionWorklet.port.postMessage('reset');
const resetParameter = this._positionWorklet.parameters.get('reset');
resetParameter.setValueAtTime(1, GodotAudio.ctx.currentTime);
resetParameter.setValueAtTime(0, GodotAudio.ctx.currentTime + 1);
return this._positionWorklet; return this._positionWorklet;
} }