Hi,
I am developing a macOS application in SwiftUI (Xcode Version 14.3 (14E222b)) which lets the users control the audio level (volume) of the running applications individually, and also enables them to change the default speaker of each running application by letting them select an audio device from a list of available audio devices connected to the Mac.
Till now, I have been able to get the following:
List of running applications using NSWorkspace.shared.runningApplications
The default audio device using kAudioHardwarePropertyDefaultOutputDevice with id and name
List of audio devices using kAudioHardwarePropertyDevices with ids and names
I am trying to get the icon of the devices using kAudioDevicePropertyIcon, but it is not working. I have written the following program to achieve the same:
var deviceIcon: CFTypeRef?
var deviceIconSize = UInt32(MemoryLayout<CFTypeRef>.size)
var deviceIconPropertyAddress = AudioObjectPropertyAddress(
mSelector: kAudioDevicePropertyIcon,
mScope: kAudioObjectPropertyScopeGlobal,
mElement: defaultOutputDeviceID)
var status = AudioObjectGetPropertyData(
defaultOutputDeviceID,
&deviceIconPropertyAddress,
0,
nil,
&deviceIconSize,
&deviceIcon)
guard status == noErr else {
print("Error getting default output device icon: \(status)")
return
}
When I run the above program, I get the following output:
Error getting default output device icon: 2003332927
defaultOutputDeviceID is the id of the default audio device. For now, I am just trying to get the icon of the default speaker which, in my case, is MacBook Air Speakers.
I have tried searching for this status code, and I found that this error is defined in AudioFile.h as kAudioFileUnspecifiedError = 'wht?', // 0x7768743F, 2003334207.
Does this mean that there is no icon for the specified deviceID, or is there something wrong with my program? Could someone please let me know how to resolve this error?
Thank you!