Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there something similar for microphone? is-mic-on? #5

Open
alessandro308 opened this issue Apr 26, 2021 · 1 comment
Open

Is there something similar for microphone? is-mic-on? #5

alessandro308 opened this issue Apr 26, 2021 · 1 comment

Comments

@alessandro308
Copy link

No description provided.

@sindresorhus
Copy link
Owner

Not that I know of, but you should be able to adapt this to check for a microphone instead:

private func getCameraProp() -> CMIOObjectID? {
var opa = CMIOObjectPropertyAddress(
mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyDevices),
mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal),
mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMaster)
)
var dataSize: UInt32 = 0
var dataUsed: UInt32 = 0
var result = CMIOObjectGetPropertyDataSize(CMIOObjectID(kCMIOObjectSystemObject), &opa, 0, nil, &dataSize)
var devices: UnsafeMutableRawPointer?
repeat {
if devices != nil {
free(devices)
devices = nil
}
devices = malloc(Int(dataSize))
result = CMIOObjectGetPropertyData(CMIOObjectID(kCMIOObjectSystemObject), &opa, 0, nil, dataSize, &dataUsed, devices)
} while result == OSStatus(kCMIOHardwareBadPropertySizeError)
var cameraId: CMIOObjectID?
if let devices = devices {
for offset in stride(from: 0, to: dataSize, by: MemoryLayout<CMIOObjectID>.size) {
let current = devices.advanced(by: Int(offset)).assumingMemoryBound(to: CMIOObjectID.self)
cameraId = current.pointee
}
}
free(devices)
return cameraId
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants