Updated on 2023-03-23 GMT+08:00

Controlling Audio and Video Devices

AVDeviceCtrl

API Description

This API is used to control local microphones, speakers, and cameras.

Precautions

This API is an asynchronous API. The return value only indicates whether the API is successfully called. The actual service processing result is returned in the corresponding callback function.

Method Definition

HWM_SDK_AGENT_API hwmsdk::HwmErrCode AVDeviceCtrl(HwmDeviceType deviceType, bool isOpen);

Callback Function

1
virtual void OnAVDeviceCtrlResult(hwmsdk::HwmErrCode ret, const char* reason, HwmDeviceType deviceType) {};

Parameter Description

Table 1 Parameter description

Parameter

Mandatory

Type

Description

HwmDeviceType

Yes

HwmDeviceType

Device type enumeration.

isOpen

Yes

bool

Whether to enable the device.

Table 2 Enumerated values of value HwmDeviceType

Enumerated Value

Description

HWM_DEVICE_TYPE_MIC

Microphone

HWM_DEVICE_TYPE_SPEAKER

Speaker

HWM_DEVICE_TYPE_CAMERA

Camera

Return Values

Table 3 Return values

Type

Description

HwmErrCode

If 0 is returned, the operation is successful. If other values are returned, the operation fails. For details about values returned upon failures, see Common Error Codes.

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
/**
* Control audio and video devices.
*/
int demoAVDeviceCtrlDlg::ClickAVDeviceCtrl()
{
    hwmsdkagent::HwmDeviceType deviceType = hwmsdkagent::HwmDeviceType::HWM_DEVICE_TYPE_MIC;
    bool isOpen = true;
    int ret = hwmsdkagent::AVDeviceCtrl(deviceType, isOpen);
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        AfxMessageBox(_T("AVDeviceCtrl error"));
    }
}