Audio: Override copy and clone methods to include missing properties #29960
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.
This PR addresses issues with the
Audioclass'scloneandcopymethods.Description
The
Object3D'sclonemethod, inherited byAudio, creates a new instance without passing additional parameters. This causes errors when cloning anAudioobject, as thelisteneris mandatory for its creation.Proposed Solution
The
clonemethod has been overridden to align with the expected behavior: reusing the existinglistenerwhen creating a newAudioinstance.The
copymethod has been overridden to correctly handle properties specific to theAudioclass, ensuring all relevant data is properly transferred.Exception Handling for
sourceType'buffer':The
playmethod regenerates thesourceinternally usingcontext.createBufferSource.'audioNode','mediaNode', or'mediaStreamNode':These source types are single-use and cannot be reused across multiple connections. A warning is logged, and these sources are excluded from the copy process to prevent misuse.
Demo of the feature with buffer souce
before
bandicam.2024-11-25.16-47-06-294.mp4
after
bandicam.2024-11-25.14-39-19-931.mp4