@@ -14,10 +14,10 @@ import 'package:sound_volume_view/src/models/device.dart';
14
14
15
15
// DOCUMENTATION HERE: https://www.nirsoft.net/utils/sound_volume_view.html#command_line
16
16
class SoundVolumeView {
17
- SoundVolumeView ({required this .softwarePath});
17
+ SoundVolumeView ({this .softwarePath});
18
18
19
19
/// [softwarePath] Absolute path of where SoundVolumeView.exe is located
20
- String softwarePath;
20
+ String ? softwarePath;
21
21
22
22
/// [_softwareName] Name of the application to run
23
23
final String _softwareName = 'SoundVolumeView.exe' ;
@@ -38,16 +38,21 @@ class SoundVolumeView {
38
38
// /SaveFileEncoding 3 = UTF-8
39
39
Future <List <Device >> _getDevices () async {
40
40
String filenameToGenerate = 'devices.json' ;
41
- String path = join (softwarePath, _softwareName);
42
- String devicesPath = join (softwarePath, filenameToGenerate);
41
+ if ( softwarePath == null ){
42
+ int lastPosition = Platform .resolvedExecutable.lastIndexOf ('\\ ' );
43
+ String pathAbsoluteSoftware = Platform .resolvedExecutable.substring (0 , lastPosition);
44
+ softwarePath = pathAbsoluteSoftware+ '\\ ' ;
45
+ }
46
+ String path = join (softwarePath! , _softwareName);
47
+ String devicesPath = join (softwarePath! , filenameToGenerate);
43
48
File file = File (devicesPath);
44
49
captureDevices.clear ();
45
50
outputDevices.clear ();
46
51
applicationDevices.clear ();
47
52
if (await file.exists ()) {
48
53
await file.delete ();
49
54
}
50
- String pathSave = join (softwarePath, filenameToGenerate);
55
+ String pathSave = join (softwarePath! , filenameToGenerate);
51
56
final Shell shell = Shell ();
52
57
await shell.run ('$path /SaveFileEncoding 3 /sjson $pathSave ' );
53
58
@@ -73,22 +78,22 @@ class SoundVolumeView {
73
78
74
79
/// [setVolume] Will lower or raise the volume to the indicated device - 0% to 100%
75
80
Future <void > setVolume (Device device, int volume) async {
76
- String path = join (softwarePath, _softwareName);
81
+ String path = join (softwarePath! , _softwareName);
77
82
final Shell shell = Shell ();
78
83
await shell.run ('$path /SetVolume ${device .name } $volume ' );
79
84
}
80
85
81
86
/// [mute] mute the device
82
87
Future <void > mute (Device device) async {
83
- String path = join (softwarePath, _softwareName);
88
+ String path = join (softwarePath! , _softwareName);
84
89
final Shell shell = Shell ();
85
90
device.muted = 'Yes' ;
86
91
await shell.run ('$path /mute ${device .name }' );
87
92
}
88
93
89
94
/// [unMute] Turn on device sound
90
95
Future <void > unMute (Device device) async {
91
- String path = join (softwarePath, _softwareName);
96
+ String path = join (softwarePath! , _softwareName);
92
97
final Shell shell = Shell ();
93
98
device.muted = 'No' ;
94
99
await shell.run ('$path /UnMute ${device .name }' );
@@ -97,7 +102,7 @@ class SoundVolumeView {
97
102
/// [setPlaybackThroughDevice] Assigns the output device to the recording line signal
98
103
Future <void > setPlaybackThroughDevice (
99
104
Device recordingDevice, Device playbackDevice) async {
100
- String path = join (softwarePath, _softwareName);
105
+ String path = join (softwarePath! , _softwareName);
101
106
final Shell shell = Shell ();
102
107
await shell.run (
103
108
'$path /SetPlaybackThroughDevice "${recordingDevice .name }" ${playbackDevice .itemID }' );
@@ -106,7 +111,7 @@ class SoundVolumeView {
106
111
/// [setListenToThisDevice] Enable or disable recording line preview
107
112
Future <void > setListenToThisDevice (Device device,
108
113
{bool listen = true }) async {
109
- String path = join (softwarePath, _softwareName);
114
+ String path = join (softwarePath! , _softwareName);
110
115
final Shell shell = Shell ();
111
116
await shell
112
117
.run ('$path /SetListenToThisDevice ${device .name } ${listen ? 1 : 0 }' );
@@ -115,7 +120,7 @@ class SoundVolumeView {
115
120
/// [setAppDefault] Allows you to set the default render/capture device for specfic application.
116
121
Future <void > setAppDefault (Device applicationDevice, Device outputDevice,
117
122
{DefaultType defaultType = DefaultType .multimedia}) async {
118
- String path = join (softwarePath, _softwareName);
123
+ String path = join (softwarePath! , _softwareName);
119
124
final Shell shell = Shell ();
120
125
switch (defaultType) {
121
126
case DefaultType .console:
@@ -140,7 +145,7 @@ class SoundVolumeView {
140
145
/// [setDefault] Output devices set all default types (Console, Multimedia, and Communications)
141
146
Future <void > setDefault (Device outputDevice,
142
147
{DefaultType defaultType = DefaultType .all}) async {
143
- String path = join (softwarePath, _softwareName);
148
+ String path = join (softwarePath! , _softwareName);
144
149
final Shell shell = Shell ();
145
150
switch (defaultType) {
146
151
case DefaultType .console:
0 commit comments