Music: fix triggered sounds sometimes not playing #48875
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes, a triggered sound played at
currentTime
wouldn't be played. This was because the current audio time had progressed slightly beyond the event time by the time we got to the code that sets up the play.The fix:
Triggered sounds might have a target play time that is very slightly in the past, specificially when they use the
currentTime
passed (slightly earlier) into the event handler code as the target play time.To compensate for this delay, if the target play time is within a tenth of a second of the current play time, then play it.
Note that we still don't play sounds older than that, because they might have been scheduled for some time ago, and Web Audio will play a sound immediately if its target time is in the past.