Skip to content

Flutter package to handle windows audio devices. Also extracts native icon to bytes in dart

License

Notifications You must be signed in to change notification settings

Far-Se/win32audio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

win32audio

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.

image

How to use

Enumerate Devices

Audio Devices

  var audioDevices = <AudioDevice>[];

    audioDevices = await Audio.enumDevices(audioDeviceType) ?? [];

Audio Mixer

  var mixerList = <ProcessVolume>[];

  mixerList = await Audio.enumAudioMixer() ?? [];

Default Device

Get

  var defaultDevice = AudioDevice();
  
  defaultDevice = (await Audio.getDefaultDevice(audioDeviceType))!;

Set

id is COM string

await Audio.setDefaultDevice(audioDevices[0].id, {bool console = false, bool multimedia = true, bool communications = false});

Switch to next Audio Device

    await Audio.switchDefaultDevice(audioDeviceType, {bool console = false, bool multimedia = true, bool communications = false});

Volume

Volume is double between 0 and 1.

Get

    final volume = await Audio.getVolume(audioDeviceType);

Set

    final volume = await Audio.setVolume(0.5,audioDeviceType);

Set Specific app volume:

    await Audio.setAudioMixerVolume(mixerList[0].processId, 0.3);

Structs/Enums

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,
}

Extra Function

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.

About

Flutter package to handle windows audio devices. Also extracts native icon to bytes in dart

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published