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(),
            )
        })?;
        self.audio_service_connected = true;

        for stream in streams {
            let client = self.client.clone();
            let stream_volume_control = 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,
            )
            // TODO(fxbug.dev/73629) This could be bad. If this fails partway we would have
            // inserted some of the volume controls but not all. The service would also think that
            // the audio core service is fully connected since that setting is not reverted.
            .await?;
            self.stream_volume_controls.insert(stream.stream_type, stream_volume_control);
        }

        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(),
            )
        })?;
        self.audio_service_connected = true;
        for stream in streams {
            let client = self.client.clone();
            let stream_volume_control = 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,
            )
            // TODO(fxbug.dev/73629) This could be bad. If this fails partway we would have
            // inserted some of the volume controls but not all. The service would also think that
            // the audio core service is fully connected since that setting is not reverted.
            .await?;
            self.stream_volume_controls.insert(stream.stream_type, stream_volume_control);
        }
        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 ( ) , ) } ) ? ; self . audio_service_connected = true ; for stream in streams { let client = self . client . clone ( ) ; let stream_volume_control = 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 , ) // TODO(fxbug.dev/73629) This could be bad. If this fails partway we would have // inserted some of the volume controls but not all. The service would also think that // the audio core service is fully connected since that setting is not reverted. . await ? ; self . stream_volume_controls . insert ( stream . stream_type , stream_volume_control ) ; } 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]