pub async fn play_sound<'a>(
    sound_player_proxy: &PlayerProxy,
    file_name: &'a str,
    id: u32,
    added_files: &mut HashSet<&'a str>,
) -> Result<(), Error> {
    // New sound, add it to the sound player set.
    if !added_files.contains(file_name) {
        added_files.insert(file_name);
        let sound_file_channel = match resource_file_channel(file_name) {
            Ok(file) => Some(file),
            Err(e) => return Err(format_err!("[earcons] Failed to convert sound file: {}", e)),
        };
        if let Some(file_channel) = sound_file_channel {
            match sound_player_proxy.add_sound_from_file(id, file_channel).await {
                Ok(_) => fx_log_info!("[earcons] Added sound to Player: {}", file_name),
                Err(e) => {
                    return Err(format_err!("[earcons] Unable to add sound to Player: {}", e));
                }
            };
        }
    }

    match sound_player_proxy.play_sound(id, AudioRenderUsage::Media).await {
        Ok(_) => fx_log_info!("[earcons] Played sound {}", file_name),
        Err(e) => fx_log_err!("[earcons] Unable to Play sound from Player: {}", e),
    };
    Ok(())
}
/// Plays a sound with the given [id] and [file_name] via the [sound_player_proxy].
///
/// The id and file_name are expected to be unique and mapped 1:1 to each other. This allows
/// the sound file to be reused without having to load it again.
Plays a sound with the given [id] and [file_name] via the [sound_player_proxy].
The id and file_name are expected to be unique and mapped 1:1 to each other. This allows
the sound file to be reused without having to load it again.
Plays a sound with the given [ id ] and [ file_name ] via the [ sound_player_proxy ] . The id and file_name are expected to be unique and mapped 1 : 1 to each other . This allows the sound file to be reused without having to load it again .
pub async fn play_sound<'a>(
    sound_player_proxy: &PlayerProxy,
    file_name: &'a str,
    id: u32,
    added_files: &mut HashSet<&'a str>,
) -> Result<(), Error> {
    // New sound, add it to the sound player set.
    if !added_files.contains(file_name) {
        added_files.insert(file_name);
        let sound_file_channel = match resource_file_channel(file_name) {
            Ok(file) => Some(file),
            Err(e) => return Err(format_err!("[earcons] Failed to convert sound file: {}", e)),
        };
        if let Some(file_channel) = sound_file_channel {
            match sound_player_proxy.add_sound_from_file(id, file_channel).await {
                Ok(_) => fx_log_info!("[earcons] Added sound to Player: {}", file_name),
                Err(e) => {
                    return Err(format_err!("[earcons] Unable to add sound to Player: {}", e));
                }
            };
        }
    }
    match sound_player_proxy.play_sound(id, AudioRenderUsage::Media).await {
        Ok(_) => fx_log_info!("[earcons] Played sound {}", file_name),
        Err(e) => fx_log_err!("[earcons] Unable to Play sound from Player: {}", e),
    };
    Ok(())
}
pub async fn play_sound < ' a > ( sound_player_proxy : & PlayerProxy , file_name : & ' a str , id : u32 , added_files : & mut HashSet < & ' a str > , ) -> Result < ( ) , Error > { // New sound, add it to the sound player set. if ! added_files . contains ( file_name ) { added_files . insert ( file_name ) ; let sound_file_channel = match resource_file_channel ( file_name ) { Ok ( file ) => Some ( file ) , Err ( e ) => return Err ( format_err ! ( " " e ) ) , } ; if let Some ( file_channel ) = sound_file_channel { match sound_player_proxy . add_sound_from_file ( id , file_channel ) . await { Ok ( _ ) => fx_log_info ! ( " " file_name ) , Err ( e ) => { return Err ( format_err ! ( " " e ) ) ; } } ; } } match sound_player_proxy . play_sound ( id , AudioRenderUsage :: Media ) . await { Ok ( _ ) => fx_log_info ! ( " " file_name ) , Err ( e ) => fx_log_err ! ( " " e ) , } ; Ok ( ( ) ) }
Plays a sound with the given [id] and [file_name] via the [sound_player_proxy].
Plays a sound with the given [ id ] and [ file_name ] via the [ sound_player_proxy ] .
sound_player_proxy
&PlayerProxy
file_name
&'a str
id
u32
added_files
&mut HashSet<&'a str>