setAppDefault method

Future<bool> setAppDefault(
  1. Device applicationDevice,
  2. Device outputDevice, {
  3. DefaultType defaultType = DefaultType.multimedia,
})

setAppDefault Allows you to set the default render/capture device for specfic application.

Implementation

Future<bool> setAppDefault(Device applicationDevice, Device outputDevice, {DefaultType defaultType = DefaultType.multimedia}) async {
  switch (defaultType) {
    case DefaultType.console:
      try {
        final command = 'SoundVolumeView /SetAppDefault "${outputDevice.commandLineFriendlyID}" 0 ${applicationDevice.processID}';
        await shell.run(command);
        return true;
      } catch( error ) {
        return false;
      }
    case DefaultType.multimedia:
      try {
        final command = 'SoundVolumeView /SetAppDefault "${outputDevice.commandLineFriendlyID}" 1 ${applicationDevice.processID}';
        await shell.run(command);
        return true;
      } catch( error ) {
        return false;
      }
    case DefaultType.communications:
      try {
        final command = 'SoundVolumeView /SetAppDefault "${outputDevice.commandLineFriendlyID}" 2 ${applicationDevice.processID}';
        await shell.run(command);
        return true;
      } catch( error ) {
        return false;
      }
    case DefaultType.all:
      try {
        final command = 'SoundVolumeView /SetAppDefault "${outputDevice.commandLineFriendlyID}" all ${applicationDevice.processID}';
        await shell.run(command);
        return true;
      } catch( error ) {
        return false;
      }
  }
}