-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Audio control - play, pause, volume, speed, loop #3948
Conversation
Co-Authored-By: Alice Cecile <alice.i.cecile@gmail.com>
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.
Real audio functionality! In bevy_audio! Very basic still, but this should give us the bare bones needed to do anything useful with it.
Code quality is solid, and this is sorely needed. We don't have the bandwidth to tackle a bevy_kira_audio integration right now, so we should be making bevy_audio incrementally better.
Unsurprisingly, a few nits to clean up.
impl<Source> fmt::Debug for AudioToPlay<Source> | ||
where | ||
Source: Asset + Decodable, | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_struct("AudioToPlay") | ||
.field("sink_handle", &self.sink_handle) | ||
.field("source_handle", &self.source_handle) | ||
.field("repeat", &self.repeat) | ||
.finish() | ||
} | ||
} |
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.
To me this looks like a manual impl of Debug that should be identical to the derive.
Am i missing something?
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.
the automatic derive needs Source
to be Debug
, but not a manual impl
... I'm not quite sure the debug impl is actually useful though, I added it to keep existing functionality
/// ``` | ||
/// # use bevy_ecs::system::{Local, Res}; | ||
/// # use bevy_asset::{Assets, Handle}; | ||
/// # use bevy_audio::AudioSink; | ||
/// // Execution of this system should be controlled by a state or input, | ||
/// // otherwise it would just toggle between play and pause every frame. | ||
/// fn pause( | ||
/// audio_sinks: Res<Assets<AudioSink>>, | ||
/// music_controller: Local<Handle<AudioSink>>, | ||
/// ) { | ||
/// if let Some(sink) = audio_sinks.get(&*music_controller) { | ||
/// if sink.is_paused() { | ||
/// sink.play() | ||
/// } else { | ||
/// sink.pause() | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` |
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.
This example is missing the assertion that the fn is a system.
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 don't think that it's needed: the only thing new in this system is the kind of asset, but systems with those parameters are already tested elsewhere. and if AudioSink
is not a valid asset, it would still fail to compile
thank you, i was just looking for this today |
Nice! Relatively uncontroversial improvements. The "weak handle" returned by
I have some thoughts about asset system changes that might make better UX possible here, but I'm not quite ready to open up that conversation. I think this is the best we can do for now. Well done! |
bors r+ |
# Objective - Add ways to control how audio is played ## Solution - playing a sound will return a (weak) handle to an asset that can be used to control playback - if the asset is dropped, it will detach the sink (same behaviour as now)
# Objective - Add ways to control how audio is played ## Solution - playing a sound will return a (weak) handle to an asset that can be used to control playback - if the asset is dropped, it will detach the sink (same behaviour as now)
# Objective - Add ways to control how audio is played ## Solution - playing a sound will return a (weak) handle to an asset that can be used to control playback - if the asset is dropped, it will detach the sink (same behaviour as now)
# Objective - Add ways to control how audio is played ## Solution - playing a sound will return a (weak) handle to an asset that can be used to control playback - if the asset is dropped, it will detach the sink (same behaviour as now)
Objective
Solution