avm1: Improve behavior of Sound when loadSound() has been called#23975
avm1: Improve behavior of Sound when loadSound() has been called#23975ChrisCPI wants to merge 1 commit into
Sound when loadSound() has been called#23975Conversation
ff54238 to
442d3c3
Compare
Corrects several behaviors of the Sound object when loading external sound. Some of the important changes: - Sound objects seem to inherit their own sound transform when loading external sound, and become "separated" from their original owner, so this has been implemented. - Added a `is_stopped` flag to the native object, which is true when `stop()` has been called. Used to prevent external sound from playing when it has finished loading. - When calling `start()`, per the docs, the second argument (loops) is now ignored when the sound is streaming.
442d3c3 to
94276fb
Compare
| /// and can then only ever control externally loaded sounds. | ||
| /// Because of this, this can be used to check if this Sound is set | ||
| /// to play external sounds. | ||
| transform: Cell<Option<SoundTransform>>, |
There was a problem hiding this comment.
Instead of giving multiple meanings to this field, can't you reuse the state enum?
There was a problem hiding this comment.
I'm not sure how I would do that exactly?
Earlier I had a separate is_external field in the native object, but it seemed redundant since it should always be true when the transform is Some, and always false when transform is None.
There was a problem hiding this comment.
You could have the transform in the state enum, e.g. a separate enum entry for when the sound is external. But that depends on how it plays with the loading/loaded states.
There was a problem hiding this comment.
But doesn't it not make sense to have it be a part of the state enum? Because e.g. if a sound was still being loaded (in the Loading state), wouldn't that mean it can't access the transform being stored in a separate state, because it's not in that state at that time?
|
If both |
|
I can look into doing that if no one disagrees with the idea. |
@kjarosh Thoughts on doing this idea? I think it could be helpful in using that to check whether the sound is external, rather than checking the transform. |
|
It depends on how this plays with the loading state, if it's unrelated to the state then yes. |
|
Putting this in draft for now - Need to do some refactoring, as it looks like the idea of the existence of a playback queue for loaded sounds is incorrect, and so I will likely remove it (effectively undoing most of #21163). What actually appears to be happening is that in FP, local sounds are loaded synchronously, so that when An easy way to observe this is to see that the var s = new Sound();
s.onLoad = function() { trace("onLoad"); }
trace("before");
s.loadSound("sound.mp3");
trace("after");In the local projector, this outputs: But when loading a remote file, it becomes asynchronous, and |
Description
Fixes #5019
Fixes #22572
This fixes several of the behaviors of the
Soundobject when playing external sound vialoadSound().When
loadSoundis called on a Sound, it appears that it enters a state of being "separated" from its original owner (even when controlling global sound). This means it can no longer control any prior sounds that were added to it viaattachSound(and can no longer attach new sounds in this way), and it inherits its own unique sound transform, not attached to any particular display object. This has now been implemented.Some of the other changes include:
is_stoppedflag to the native object, which is true whenstop()has been called. Used to prevent external sound from playing when it has finished loading.start(), per the docs, the second argument (loops) is now ignored when the sound is streaming.loadSoundis called again on the object, any external sounds it was playing are stopped, streaming or not.Testing
Several tests added to cover this.
Checklist
set_sound_transform_with_handlefunction)