Hi,
I can see that version 1.6.2 introduced support for PTZ cameras, but I can’t find any information in regards to how to initialize and allow control over the camera.
Has anyone been able to do this on macOS?
I’m able to list all my available cameras and check for the ability to control them once a user selects the camera.
The code I have been testing with looks like this:
func fetchCameras() {
let videoHelper = ZMVideoSDK.shared().getVideoHelper()
cameraDevices = videoHelper.getCameraList() ?? []
// Check which camera is currently selected
if let selectedCamera = cameraDevices.first(where: { $0.isSelectedDevice }) {
self.selectedCameraID = selectedCamera.deviceID
print("Found selected camera. \(selectedCamera.deviceName)")
canControlCamera()
} else {
// No camera is selected or there are no cameras
self.selectedCameraID = nil
}
}
func selectCamera(deviceID: String?) {
let videoHelper = ZMVideoSDK.shared().getVideoHelper()
if let cameraDeviceID = deviceID {
let result = videoHelper.selectCamera(cameraDeviceID)
print("Camera switched successfully? : \(result)")
canControlCamera()
} else {
print("selectCamera: Invalid Device ID")
}
}
func canControlCamera() {
var canControl: ObjCBool = false
let result = ZMVideoSDK.shared().getVideoHelper().canControlCamera(&canControl, deviceID: selectedCameraID)
DispatchQueue.main.async {
self.userCanControlCamera = canControl.boolValue
let cameraName = self.cameraDevices.first(where: { $0.deviceID == self.selectedCameraID })?.deviceName
print("\(self.errorMessage(for: result)). Can app control camera \(cameraName)? : \(self.userCanControlCamera)")
}
}
func moveCameraLeft() {
let range:UInt32 = 20
let cameraName = self.cameraDevices.first(where: { $0.deviceID == self.selectedCameraID })?.deviceName
let result = ZMVideoSDK.shared().getVideoHelper().turnCameraLeft(range, deviceID: selectedCameraID)
print("Move \(cameraName) left: \(errorMessage(for: result))")
}
private func errorMessage(for error: ZMVideoSDKErrors) -> String {
switch error {
case ZMVideoSDKErrors_Success:
return "Success"
case ZMVideoSDKErrors_Wrong_Usage:
return "Error: Wrong usage of the SDK"
case ZMVideoSDKErrors_Internal_Error:
return "Error: Internal SDK error"
case ZMVideoSDKErrors_Uninitialize:
return "Error: SDK not initialized"
case ZMVideoSDKErrors_Memory_Error:
return "Error: Memory issues encountered"
case ZMVideoSDKErrors_Load_Module_Error:
return "Error: Failed to load a module"
case ZMVideoSDKErrors_UnLoad_Module_Error:
return "Error: Failed to unload a module".
case ZMVideoSDKErrors_Auth_Error:
return "Error: Authentication failed"
case ZMVideoSDKErrors_JoinSession_NoSessionName:
return "Error: No session name provided for joining session"
case ZMVideoSDKErrors_Wrong_Usage:
return "Error: Wrong Usage"
case ZMVideoSDKErrors_Internal_Error:
return "Error: Internal Error"
case ZMVideoSDKErrors_Uninitialize:
return "Error: Uninitialize"
case ZMVideoSDKErrors_Memory_Error:
return "Error: Memory Error"
case ZMVideoSDKErrors_Load_Module_Error:
return "Error: Load Module Error"
case ZMVideoSDKErrors_UnLoad_Module_Error:
return "Error: Unload Module Error"
case ZMVideoSDKErrors_Invalid_Parameter:
return "Error: Invalid Parameter"
case ZMVideoSDKErrors_Call_Too_Frequently:
return "Error: Call too frequently"
case ZMVideoSDKErrors_No_Impl :
return "Error: No impl"
case ZMVideoSDKErrors_Dont_Support_Feature:
return "Error: Dont support feature"
case ZMVideoSDKErrors_Unknown:
return "Error: Unkown"
case ZMVideoSDKErrors_Remove_Folder_Fail:
return "Remove Folder Fail"
// Add additional cases for other specific errors..
default:
return "Unknown error occurred with code: \(error.rawValue)"
}
}
I get the following outputs when calling the methods
ZMVideoSDKErrors_Success . Can app control camera Optional(“UVC Camera”)? : false
** Move Optional(“UVC Camera”) left: Error: Wrong usage of the SDK**
The current camera I’m working with is
Does this feature only work with certain types of cameras? @michael.zoom @rehema.zoom