Remove TODO and add docs about limitations of PlaybackMode::Once (#16769)

# Objective

Fixes #12359

## Solution

Implement alternative number 4.

https://github.com/bevyengine/bevy/issues/12359#issuecomment-2536422301
> 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
This commit is contained in:
Rob Parrett 2024-12-11 16:57:48 -08:00 committed by GitHub
parent e5d7fb4beb
commit 33a1a5568c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
@ -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),