Re-implement custom audio files support. (#379)
* reimplement custom audio loading for `toast` and `key_click` using `from_mp3` * run cargo fmt * `try_bytes_from_config`: output with `log::trace` when file cannot be opened * rewrite `try_bytes_from_config` * use file `read_to_end`, log categories * edit `register_wgui_samples` * rework audio functions for loading custom wgui sounds oh hey, it works! * clean up * allow custom `startup` and `app_start` sounds these sounds are loaded on-demand and never registered; this behaviour is unchanged * edit `bytes_from_config` outputs * use return value of `read_to_end` instead of `len()` for reported file size * implement suggested changes - remove now-unused `register_mp3_sample_from_assets` function - replace implementation of `try_bytes_from_config` - missing the `real_path` context * swap out `context`s for `inspect_err`s with closures to output `real_path` * clean up `audio.rs` - remove unused import - unify capitalisation + quotes in output messages.
This commit is contained in:
@@ -183,10 +183,19 @@ impl<T: 'static> Frontend<T> {
|
||||
|
||||
fn play_sound(&mut self, audio_system: &mut audio::AudioSystem, sound_type: SoundType) -> anyhow::Result<()> {
|
||||
let mut assets = self.globals.assets_builtin();
|
||||
let sample = audio::AudioSample::from_mp3(&assets.load_from_path(match sound_type {
|
||||
|
||||
let path = match sound_type {
|
||||
SoundType::Startup => "sound/startup.mp3",
|
||||
SoundType::Launch => "sound/app_start.mp3",
|
||||
})?)?;
|
||||
};
|
||||
|
||||
// try loading a custom sound; if one doesn't exist (or it failed to load), use the built-in asset
|
||||
let sound_bytes = match audio::AudioSample::try_bytes_from_config(path) {
|
||||
Ok(bytes) => bytes,
|
||||
Err(_) => assets.load_from_path(path)?.into(),
|
||||
};
|
||||
|
||||
let sample = audio::AudioSample::from_mp3(&*sound_bytes)?;
|
||||
audio_system.play_sample(&sample);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user