Skip to content

Add extension method for App in bevy_audio that register custom Decodable types #6364

@harudagondi

Description

@harudagondi

What problem does this solve or what need does it fill?

Related to #6362. Creating custom Decodable types requires boilerplate.

What solution would you like?

Create an extension trait for App.

trait AddAudioSource {
	fn add_audio_source<Au>(&mut self) -> &mut Self
	where
		Au: Decodable + Asset;
}

impl AddAudioSource for App {
	fn add_audio_source<Au>(&mut self) -> &mut Self
	where
		Au: Decodable + Asset
	{
		self.add_asset::<Au>
			.init_resource::<Audio<Au>>()
			.init_non_send_resource::<AudioOutput<Au>>()
			.add_system_to_stage(CoreStage::PostUpdate, play_queued_audio_system::<Au>)
	}
}

What alternative(s) have you considered?

Simply do not do this. Manually register audio sources.

Additional context

See harudagondi/bevy_fundsp#6, especially in lib.rs and backend/bevy_audio.rs.

Also see bevy_oddio's implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AudioSounds playback and modificationC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions