async fn check_and_bind_volume_controls(
        &mut self,
        streams: &[AudioStream],
    ) -> ControllerStateResult {
        if self.audio_service_connected {
            return Ok(());
        }

        let service_result = self
            .client
            .get_service_context()
            .connect::<fidl_fuchsia_media::AudioCoreMarker>()
            .await;

        let audio_service = service_result.map_err(|_| {
            ControllerError::ExternalFailure(
                SettingType::Audio,
                "fuchsia.media.audio".into(),
                "connect for audio_core".into(),
            )
        })?;

        // The stream_volume_controls are generated in two steps instead of
        // one so that if one of the bindings fails during the first loop,
        // none of the streams are modified.
        let mut stream_tuples = Vec::new();
        for stream in streams {
            let client = self.client.clone();

            // Generate a tuple with stream type and StreamVolumeControl.
            stream_tuples.push((
                stream.stream_type,
                StreamVolumeControl::create(
                    &audio_service,
                    *stream,
                    Some(Arc::new(move || {
                        // When the StreamVolumeControl exits early, inform the
                        // proxy we have exited. The proxy will then cleanup this
                        // AudioController.
                        let client = client.clone();
                        fasync::Task::spawn(async move {
                            client
                                .notify(Event::Exited(Err(ControllerError::UnexpectedError(
                                    "stream_volume_control exit".into(),
                                ))))
                                .await;
                        })
                        .detach();
                    })),
                    None,
                )
                .await?,
            ));
        }

        stream_tuples.into_iter().for_each(|(stream_type, stream_volume_control)| {
            self.stream_volume_controls.insert(stream_type, stream_volume_control);
        });
        self.audio_service_connected = true;

        Ok(())
    }
/// Populates the local state with the given [streams] and binds it to the audio core service.
Populates the local state with the given [streams] and binds it to the audio core service.
Populates the local state with the given [ streams ] and binds it to the audio core service .
async fn check_and_bind_volume_controls(
        &mut self,
        streams: &[AudioStream],
    ) -> ControllerStateResult {
        if self.audio_service_connected {
            return Ok(());
        }
        let service_result = self
            .client
            .get_service_context()
            .connect::<fidl_fuchsia_media::AudioCoreMarker>()
            .await;
        let audio_service = service_result.map_err(|_| {
            ControllerError::ExternalFailure(
                SettingType::Audio,
                "fuchsia.media.audio".into(),
                "connect for audio_core".into(),
            )
        })?;
        // The stream_volume_controls are generated in two steps instead of
        // one so that if one of the bindings fails during the first loop,
        // none of the streams are modified.
        let mut stream_tuples = Vec::new();
        for stream in streams {
            let client = self.client.clone();
            // Generate a tuple with stream type and StreamVolumeControl.
            stream_tuples.push((
                stream.stream_type,
                StreamVolumeControl::create(
                    &audio_service,
                    *stream,
                    Some(Arc::new(move || {
                        // When the StreamVolumeControl exits early, inform the
                        // proxy we have exited. The proxy will then cleanup this
                        // AudioController.
                        let client = client.clone();
                        fasync::Task::spawn(async move {
                            client
                                .notify(Event::Exited(Err(ControllerError::UnexpectedError(
                                    "stream_volume_control exit".into(),
                                ))))
                                .await;
                        })
                        .detach();
                    })),
                    None,
                )
                .await?,
            ));
        }
        stream_tuples.into_iter().for_each(|(stream_type, stream_volume_control)| {
            self.stream_volume_controls.insert(stream_type, stream_volume_control);
        });
        self.audio_service_connected = true;
        Ok(())
    }
async fn check_and_bind_volume_controls ( & mut self , streams : & [ AudioStream ] , ) -> ControllerStateResult { if self . audio_service_connected { return Ok ( ( ) ) ; } let service_result = self . client . get_service_context ( ) . connect :: < fidl_fuchsia_media :: AudioCoreMarker > ( ) . await ; let audio_service = service_result . map_err ( | _ | { ControllerError :: ExternalFailure ( SettingType :: Audio , " " . into ( ) , " " . into ( ) , ) } ) ? ; // The stream_volume_controls are generated in two steps instead of // one so that if one of the bindings fails during the first loop, // none of the streams are modified. let mut stream_tuples = Vec :: new ( ) ; for stream in streams { let client = self . client . clone ( ) ; // Generate a tuple with stream type and StreamVolumeControl. stream_tuples . push ( ( stream . stream_type , StreamVolumeControl :: create ( & audio_service , * stream , Some ( Arc :: new ( move | | { // When the StreamVolumeControl exits early, inform the // proxy we have exited. The proxy will then cleanup this // AudioController. let client = client . clone ( ) ; fasync :: Task :: spawn ( async move { client . notify ( Event :: Exited ( Err ( ControllerError :: UnexpectedError ( " " . into ( ) , ) ) ) ) . await ; } ) . detach ( ) ; } ) ) , None , ) . await ? , ) ) ; } stream_tuples . into_iter ( ) . for_each ( | ( stream_type , stream_volume_control ) | { self . stream_volume_controls . insert ( stream_type , stream_volume_control ) ; } ) ; self . audio_service_connected = true ; Ok ( ( ) ) }
Populates the local state with the given [streams] and binds it to the audio core service.
Populates the local state with the given [ streams ] and binds it to the audio core service .
&mut self
streams
&[AudioStream]
&mut self
streams
&[AudioStream]