flixel icon indicating copy to clipboard operation
flixel copied to clipboard

Rework FlxSound load methods

Open ACrazyTown opened this issue 3 months ago • 14 comments

Closes #3466.

  • Deprecates loadEmbedded(), loadStream() and loadByteArray() and replaces them with load() and loadFromURL().
  • Deprecate FlxG.sound.stream() for FlxG.sound.loadFromURL() to stay consistent
  • ~~Add loadStreamed() to allow loading streamed sounds. Additionally adds required functionality to FlxG.assets~~ https://github.com/HaxeFlixel/flixel/pull/3518
  • Modifies FlxSoundAsset to allow passing in a ByteArray.

ACrazyTown avatar Sep 14 '25 19:09 ACrazyTown

Is this something that can be unit tested? I'm genuinely not sure.

Geokureli avatar Sep 17 '25 17:09 Geokureli

I'm a bit unfamiliar when it comes to unit tests. Maybe we could check if the internal sound (_sound) is created and not null to see if Flixel managed to detect the data properly. I'm not sure if we can check if the sound loaded properly though, maybe checking length?

ACrazyTown avatar Sep 17 '25 18:09 ACrazyTown

NVM, FlxSoundTest doesn't actually test any of the existing args, so let's look into that in the future

Geokureli avatar Sep 17 '25 18:09 Geokureli

Just gonna say it, a byte array isn't "embedded", so it's odd to use this to load it... Maybe we should add a new load() method and deprecate loadEmbedded (maybe in a later version)?

Thoughts?

Geokureli avatar Sep 17 '25 18:09 Geokureli

Just gonna say it, a byte array isn't "embedded", so it's odd to use this to load it... Maybe we should add a new load() method and deprecate loadEmbedded (maybe in a later version)?

Thoughts?

Sounds good. While we're at it, I think it might be worth renaming loadStream() as well. From what I can tell the main purpose of it seems to be to load sounds from web locations, but there's a different concept of "streamed sounds" that would be nice to have built in.

Streamed sounds are helpful to use less memory when dealing with large music tracks for example. Instead of loading the entire file and playing it, they load (and unload) smaller chunks of data as they play.

We could have something like load(), loadFromURL() and loadStreamed() (but maybe that could be an argument in load() instead)

ACrazyTown avatar Sep 17 '25 19:09 ACrazyTown

loadFromURL seems best to me

Also Openfl does have the ability to "stream" audio, but I don't know if flixel leverages this

Geokureli avatar Sep 17 '25 19:09 Geokureli

Also Openfl does have the ability to "stream" audio, but I don't know if flixel leverages this

I believe it doesn't. I think we just have to use Assets.getMusic() (which internally sets up the sound to be streamed) instead of Assets.getSound()

ACrazyTown avatar Sep 17 '25 19:09 ACrazyTown

Also Openfl does have the ability to "stream" audio, but I don't know if flixel leverages this

I believe it doesn't. I think we just have to use Assets.getMusic() (which internally sets up the sound to be streamed) instead of Assets.getSound()

I forgot how I did it, but there's a way on html5 to stream a sound from the web

Geokureli avatar Sep 17 '25 23:09 Geokureli

Should I repurpose this and also include the load() changes here or should that be done in a seperate PR?

ACrazyTown avatar Sep 18 '25 14:09 ACrazyTown

Should I repurpose this and also include the load() changes here or should that be done in a seperate PR?

Please include that change, here

Geokureli avatar Sep 18 '25 15:09 Geokureli

There's still some quirks I need to figure out related to audio streaming. To not bloat this PR I'll strip out parts related to audio streaming and re-add them later in a separate PR.

ACrazyTown avatar Oct 06 '25 09:10 ACrazyTown

I misread this as rework flxsound like entirely, because i've did reworked the flxsounds once in one of gulp... FNF engine, which is still a mess that i was thinking of making a pull request on it later when its stable

Raltyro avatar Oct 06 '25 09:10 Raltyro

Maybe don't restrict MUSIC asset type to lime_vorbis in the future? since who knows if lime is going to add another format being able to streamed beside vorbis

Raltyro avatar Oct 06 '25 09:10 Raltyro

Maybe don't restrict MUSIC asset type to lime_vorbis in the future? since who knows if lime is going to add another format being able to streamed beside vorbis

Yeah, that's something that could be addressed in a patch/minor release with a compiler conditional. I have to stick to checking lime_vorbis and messing with the VorbisFile API currently because Lime doesn't really have a proper cross-platform way to check if audio streaming is supported.

ACrazyTown avatar Oct 06 '25 09:10 ACrazyTown

Thanks!

Geokureli avatar Dec 15 '25 00:12 Geokureli