Skip to content

Commit

Permalink
Remove TODO and add docs about limitations of PlaybackMode::Once (b…
Browse files Browse the repository at this point in the history
…evyengine#16769)

# Objective

Fixes bevyengine#12359

## Solution

Implement alternative number 4.

bevyengine#12359 (comment)
> I don't think that I agree with the premise of this issue anymore. I
am not sure that entities "magically" despawning themselves or
components removing themselves make for great defaults in an "ECS-based
API". This behavior is likely to be just as surprising to people.
>
> I think that the lack of sink re-usability should be treated as a bug
and possibly the documentation improved to reflect the current
limitations if it doesn't seem like a fix is forthcoming.
> -- me
  • Loading branch information
rparrett authored Dec 12, 2024
1 parent e5d7fb4 commit 33a1a55
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/bevy_audio/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl Volume {
#[derive(Debug, Clone, Copy, Reflect)]
pub enum PlaybackMode {
/// Play the sound once. Do nothing when it ends.
///
/// Note: It is not possible to reuse an `AudioPlayer` after it has finished playing and
/// the underlying `AudioSink` or `SpatialAudioSink` has been drained.
///
/// To replay a sound, the audio components provided by `AudioPlayer` must be removed and
/// added again.
Once,
/// Repeat the sound forever.
Loop,
Expand Down Expand Up @@ -77,13 +83,18 @@ pub struct PlaybackSettings {

impl Default for PlaybackSettings {
fn default() -> Self {
// TODO: what should the default be: ONCE/DESPAWN/REMOVE?
Self::ONCE
}
}

impl PlaybackSettings {
/// Will play the associated audio source once.
///
/// Note: It is not possible to reuse an `AudioPlayer` after it has finished playing and
/// the underlying `AudioSink` or `SpatialAudioSink` has been drained.
///
/// To replay a sound, the audio components provided by `AudioPlayer` must be removed and
/// added again.
pub const ONCE: PlaybackSettings = PlaybackSettings {
mode: PlaybackMode::Once,
volume: Volume(1.0),
Expand Down

0 comments on commit 33a1a55

Please sign in to comment.