A library to get Audio Devices on Windows.
Also you can get volume and set Master volume or individual application volume
Also includes a utilitary function nativeIconToBytes
that can be used for other purposes rather than audio device.
var audioDevices = <AudioDevice>[];
audioDevices = await Audio.enumDevices(audioDeviceType) ?? [];
var mixerList = <ProcessVolume>[];
mixerList = await Audio.enumAudioMixer() ?? [];
var defaultDevice = AudioDevice();
defaultDevice = (await Audio.getDefaultDevice(audioDeviceType))!;
id
is COM string
await Audio.setDefaultDevice(audioDevices[0].id, {bool console = false, bool multimedia = true, bool communications = false});
await Audio.switchDefaultDevice(audioDeviceType, {bool console = false, bool multimedia = true, bool communications = false});
Volume is double between 0 and 1.
final volume = await Audio.getVolume(audioDeviceType);
final volume = await Audio.setVolume(0.5,audioDeviceType);
await Audio.setAudioMixerVolume(mixerList[0].processId, 0.3);
class AudioDevice {
String id = "";
String name = "";
String iconPath = "";
int iconID = 0;
bool isActive = false;
}
class ProcessVolume {
int processId = 0;
String processPath = "";
double maxVolume = 1.0;
double peakVolume = 0.0;
}
enum AudioDeviceType {
output,
input,
}
nativeIconToBytes
extracts icon either from EXE file or dll file and store it as UInt8List
Map<String, Uint8List?> _audioIcons = {};
_audioIcons = {};
for (var audioDevice in audioDevices) {
if (_audioIcons[audioDevice.id] == null) {
_audioIcons[audioDevice.id] = await nativeIconToBytes(audioDevice.iconPath, iconID: audioDevice.iconID);
}
}
///....
widget: (_audioIcons.containsKey(audioDevices[index].id))
? Image.memory(
_audioIcons[audioDevices[index].id] ?? Uint8List(0),
width: 32,
height: 32,
)
: const Icon(Icons.spoke_outlined),
In the same way I've made a class WinIcons() with these functions:
extractFileIcon
that extract an asociated icon from any file.
extractWindowIcon
which extracts an icon from HWND/ Window Handle
extractIconHandle
which extracts an icon from HICON/ Icon Handle.