-
Notifications
You must be signed in to change notification settings - Fork 490
Add support for music streaming #3518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
What exactly is "streaming"? I assume it's playing a sound without having to put the entire song in memory, first. How would I test this? Which targets does this work on, and do I need to prevent the asset from being preloaded via the project.xml, or something? |
|
I think if we're gonna do this we need to be really clear about when this can be done and what it's actually doing. I'm thinking we wrap these methods in |
|
How about just wrapping |
…lixel into feat/audio-stream-2
|
Let me know if these changes are good. I've also added a helper similar to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually having some doubts about this now. I think lime's way of differentiating "loading" vs "streaming" with "sound" vs "music" is confusing. I don't think people will see these methods and intuit this difference, and rather than copying lime's wording I say we come up with something that better highlights the differences.
My immediate thoughts:
- People may want to stream sounds and/or load music, or may not expect any differences between the two
FlxG.assets.getFoomethods are always syncronous, they return the usable asset, whereFlxG.assets.loadFoomethods are async, they return aFuture<T>to use while it fetches the asset. Streaming is definitely closer to a "get" but perhaps we should add a third option, or an optional arg to get methods.- It's possible I wanted these methods wrapped in
#ifonly because of this lack of clarity. Another thing to consider is always having them and warning when it's not available, like you did in some cases here. Though, if we can tell devs - at compile time -that streaming is definitely not possible, that's also helpful - FlxG.assets.canBeStreamed(asset, type) seems helpful to everyone trying to add streaming
Co-authored-by: George Kurelic <[email protected]>
I'd understand loading music, but there's really never a need to stream sounds. Doing so has more overhead and no gains. I do agree that the sound/music naming convention can be confusing though.
I think this is a bit of a weird case because streaming is really only applicable to audio files. I don't think it would make sense to add a new method/argument to all of the methods if they'll be useless in a lot of cases. It also technically is synchronous. The sound is ready to be used immediately. Sure, it loads data behind the scenes, but to the user it's as if it was immediately fully loaded. Flixel's asset front end seems to be modeled pretty closely after OpenFL's assets, so I'm not sure how we'd squeeze in a new API that's not present there. Would a
I left the
Same as I mentioned above, I don't understand why we'd pass in a type here since streaming is only applicable to audio. |
This is correct, for nearly everyone's use case. I just meant, people won't intuitively connect "music" to streaming and "sounds" to fully loading. But to be pedantic, voice acted lines may be non-musical and long enough to warrant streaming
Additionally, adding an optional
I agree, here is my plan:
P.S.: Fwiw, if we add video or gif assets it may be possible to stream them, text and binary streams exist, but for now we don't need to worry about that. |
|
How about this for a little more consistency with the other methods? public dynamic function streamSoundUnsafe(id:String):Sound; // calls Assets.getMusic(id)
public function streamSound(id:String, ?logStyle:LogStyle):Sound; // calls streamSoundUnsafe(addSoundExtIf(id)), logs if missing
public function streamSoundAddExt(id:String, ?logStyle:LogStyle):Sound; // calls streamSoundUnsafe(addSoundExt(id)), logs if missingI've removed the
|
Excellent, I forgot about those methods
Maybe we should include the useCache arg, default to false, and add documentation explaining these issues. Maybe putting the spotlight on these issues will lead to a fix for lime. Also if caching works for streaming a single music file, that use case is common enough to justify it.
Yes, please |
I don't think it's a bug, it's just something that you should not do. A VorbisFile is really just a file pointer like you'd get by calling |
Thanks for clarifying, lets scrap the arg, then |
|
Some change notes
Let me know if this looks right to you @ACrazyTown. Apparently I can't request you to review your own PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't let me request changes (I can only comment), but overall this looks good!
Co-authored-by: ACrazyTown <[email protected]>
|
I'm getting a strange result in a test. will continue this tonight Edit: The issue was unrelated |
|
Thanks! |
|
Now we can have a holly jolly Christmas :) |


Been testing this internally and it's been working well so I thought it'd be time to do a PR.
In short:
FLX_STREAM_SOUNDdefine, which is used to check when sound streaming is supportedAssetsFrontEndstreamSoundUnsafe(),streamSound(),streamSoundAddExt(),canStreamSound()FlxSound: adds theFlxSound.loadStreamed()method which uses audio streaming under the hood. Very useful for large audio tracks as it loads chunks of data while it plays which results in small memory usage.FlxG.sound.loadStreamed()which is a helper for this!Audio streaming is currently only supported when targeting native and using OGG files, this is due to a limitation with Lime. I've been poking around trying to get streaming to work on HTML5 as well. I have a proof of concept, but it might require changes to OpenFL, so it'll be implemented in a later PR once that's all figured out.
Further considerations:
FlxG.sound.playMusic()use streaming?Should we add a helper method akin toFlxG.sound.load()but for streamed sounds?