Last active
November 24, 2019 23:41
-
-
Save suzp1984/0296a657cef6b7d207a7034979406fe1 to your computer and use it in GitHub Desktop.
os x: get default audio input device volume
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getDefaultAudioInputVolume() -> Float32? { | |
| var audioVolumeAddr = AudioObjectPropertyAddress( | |
| mSelector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume, | |
| mScope: kAudioObjectPropertyScopeInput, | |
| mElement: kAudioObjectPropertyElementMaster | |
| ) | |
| guard let audioInputDevice = getDefaultAudioInputDevice() else { | |
| return nil | |
| } | |
| var audioInputVolume: Float32 = 0 | |
| var propertySize = UInt32(MemoryLayout.size(ofValue: audioInputVolume)) | |
| let error = AudioObjectGetPropertyData(AudioObjectID(audioInputDevice), | |
| &audioVolumeAddr, | |
| 0, | |
| nil, | |
| &propertySize, | |
| &audioInputVolume) | |
| if error != kAudioHardwareNoError { | |
| return nil | |
| } | |
| return audioInputVolume | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment