diff --git a/BassBoom.Basolia/Devices/DeviceTools.cs b/BassBoom.Basolia/Devices/DeviceTools.cs
index 13c59f2..2df5662 100644
--- a/BassBoom.Basolia/Devices/DeviceTools.cs
+++ b/BassBoom.Basolia/Devices/DeviceTools.cs
@@ -31,8 +31,8 @@ namespace BassBoom.Basolia.Devices
///
public static class DeviceTools
{
- internal static string activeDriver = "";
- internal static string activeDevice = "";
+ internal static string activeDriver;
+ internal static string activeDevice;
[StructLayout(LayoutKind.Sequential)]
public struct DriverList
diff --git a/BassBoom/Views/MainView.axaml b/BassBoom/Views/MainView.axaml
index 2ecaff4..0aca0cb 100644
--- a/BassBoom/Views/MainView.axaml
+++ b/BassBoom/Views/MainView.axaml
@@ -48,8 +48,11 @@
-
+
+
+ Determine device and driver
+
diff --git a/BassBoom/Views/MainView.axaml.cs b/BassBoom/Views/MainView.axaml.cs
index 9b07891..ce2a0d2 100644
--- a/BassBoom/Views/MainView.axaml.cs
+++ b/BassBoom/Views/MainView.axaml.cs
@@ -43,11 +43,14 @@ public MainView()
InitializeComponent();
DataContext = new BassBoomData(this);
PathToMp3.TextChanged += CheckPath;
+ DetermineDevice.IsCheckedChanged += MakeDeviceDeterministic;
}
- public void CheckPath(object sender, TextChangedEventArgs e)
+ internal void EnablePlay()
{
- if (File.Exists(PathToMp3.Text) && (!string.IsNullOrEmpty(((BassBoomData)DataContext).selectedDevice)))
+ if (File.Exists(PathToMp3.Text) &&
+ ((!DetermineDevice.IsChecked.Value && !string.IsNullOrEmpty(((BassBoomData)DataContext).selectedDevice)) ||
+ DetermineDevice.IsChecked.Value))
{
PlayButton.IsEnabled = true;
GetDuration.IsEnabled = true;
@@ -58,13 +61,19 @@ public void CheckPath(object sender, TextChangedEventArgs e)
GetDuration.IsEnabled = false;
}
}
+
+ private void CheckPath(object sender, TextChangedEventArgs e) =>
+ EnablePlay();
+
+ private void MakeDeviceDeterministic(object sender, RoutedEventArgs e) =>
+ ((BassBoomData)DataContext).HandleDeviceButtons();
}
public class BassBoomData
{
private readonly MainView view;
- internal string selectedDriver = "";
- internal string selectedDevice = "";
+ internal string selectedDriver;
+ internal string selectedDevice;
internal bool paused = false;
public void GetDuration()
@@ -113,12 +122,6 @@ public async Task PlayAsync()
view.PauseButton.IsEnabled = true;
view.StopButton.IsEnabled = true;
await PlaybackTools.PlayAsync();
- view.PlayButton.IsEnabled = true;
- view.GetDuration.IsEnabled = true;
- view.SelectDevice.IsEnabled = true;
- view.SelectDriver.IsEnabled = true;
- view.PauseButton.IsEnabled = false;
- view.StopButton.IsEnabled = false;
}
catch (BasoliaException bex)
{
@@ -140,6 +143,11 @@ public async Task PlayAsync()
{
if (FileTools.IsOpened && !paused)
FileTools.CloseFile();
+ view.PlayButton.IsEnabled = true;
+ view.GetDuration.IsEnabled = true;
+ view.PauseButton.IsEnabled = false;
+ view.StopButton.IsEnabled = false;
+ HandleDeviceButtons();
}
}
@@ -147,14 +155,7 @@ public void Pause()
{
try
{
- view.PlayButton.IsEnabled = true;
- view.GetDuration.IsEnabled = false;
- view.SelectDevice.IsEnabled = false;
- view.SelectDriver.IsEnabled = false;
- view.PauseButton.IsEnabled = false;
- view.StopButton.IsEnabled = true;
PlaybackTools.Pause();
- paused = true;
}
catch (BasoliaException bex)
{
@@ -172,18 +173,22 @@ public void Pause()
$"{ex.Message}", ButtonEnum.Ok);
dialog.ShowAsync();
}
+ finally
+ {
+ view.PlayButton.IsEnabled = true;
+ view.GetDuration.IsEnabled = false;
+ view.SelectDevice.IsEnabled = false;
+ view.SelectDriver.IsEnabled = false;
+ view.PauseButton.IsEnabled = false;
+ view.StopButton.IsEnabled = true;
+ paused = true;
+ }
}
public void Stop()
{
try
{
- view.PlayButton.IsEnabled = true;
- view.GetDuration.IsEnabled = true;
- view.SelectDevice.IsEnabled = true;
- view.SelectDriver.IsEnabled = true;
- view.PauseButton.IsEnabled = false;
- view.StopButton.IsEnabled = false;
PlaybackTools.Stop();
}
catch (BasoliaException bex)
@@ -206,6 +211,11 @@ public void Stop()
{
if (FileTools.IsOpened)
FileTools.CloseFile();
+ view.PlayButton.IsEnabled = true;
+ view.GetDuration.IsEnabled = true;
+ view.PauseButton.IsEnabled = false;
+ view.StopButton.IsEnabled = false;
+ HandleDeviceButtons();
}
}
@@ -287,6 +297,24 @@ public void SelectDevice()
}
}
+ internal void HandleDeviceButtons()
+ {
+ if (view.DetermineDevice.IsChecked.Value)
+ {
+ selectedDevice = null;
+ selectedDriver = null;
+ view.SelectDevice.IsEnabled = false;
+ view.SelectDriver.IsEnabled = false;
+ }
+ else
+ {
+ if (!string.IsNullOrEmpty(selectedDriver))
+ view.SelectDevice.IsEnabled = true;
+ view.SelectDriver.IsEnabled = true;
+ }
+ view.EnablePlay();
+ }
+
internal BassBoomData(MainView window)
{
view = window;