Skip to content

Commit

Permalink
imp - Enable buttons only when state is appropriate
Browse files Browse the repository at this point in the history
We need to enable buttons only when state is appropriate

---

When the file is found and the device is selected, allow playing.

This is temporary, and will be reverted when driver and device auto-detection is implemented in the Basolia codebase.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Aug 26, 2023
1 parent 0fe72e1 commit 8196b35
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 10 additions & 0 deletions BassBoom.Basolia/Playback/PlaybackTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ namespace BassBoom.Basolia.Playback
/// </summary>
public static class PlaybackTools
{
private static bool _playing = false;

/// <summary>
/// Checks to see whether the music is playing
/// </summary>
public static bool Playing =>
_playing;

public static void Play()
{
InitBasolia.CheckInited();
Expand Down Expand Up @@ -85,6 +93,7 @@ public static void Play()
int done = 0;
int err = (int)mpg123_errors.MPG123_OK;
int samples = 0;
_playing = true;
do
{
int played;
Expand All @@ -99,6 +108,7 @@ public static void Play()
samples += played / frameSize;
Debug.WriteLine($"S: {samples}");
} while (done != 0 && err == (int)mpg123_errors.MPG123_OK);
_playing = false;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions BassBoom/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
<StackPanel>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, Auto, Auto" Margin="15">
<Label Grid.Row="0" Grid.Column="0">File path:</Label>
<TextBox Name="PathToMp3" Grid.Row="0" Grid.Column="1" Watermark="Path to the MP3 file"></TextBox>
<TextBox Name="PathToMp3" Grid.Row="0" Grid.Column="1" Watermark="Path to the MP3 file" x:CompileBindings="False"></TextBox>
<TextBlock Name="DurationLabel" Grid.Row="1" Grid.Column="0">Duration:</TextBlock>
</Grid>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, Auto, Auto" Margin="15">
<Button Grid.Row="2" Grid.Column="0" Name="GetDuration" x:CompileBindings="False" Command="{Binding GetDuration}">Get duration</Button>
<Button Grid.Row="2" Grid.Column="1" Name="PlayButton" x:CompileBindings="False" Command="{Binding Play}">Play</Button>
<Button Grid.Row="2" Grid.Column="0" Name="GetDuration" x:CompileBindings="False" Command="{Binding GetDuration}" IsEnabled="False">Get duration</Button>
<Button Grid.Row="2" Grid.Column="1" Name="PlayButton" x:CompileBindings="False" Command="{Binding Play}" IsEnabled="False">Play</Button>
<Button Grid.Row="2" Grid.Column="2" Name="SelectDriver" x:CompileBindings="False" Command="{Binding SelectDriver}">Select driver...</Button>
<Button Grid.Row="2" Grid.Column="3" Name="SelectDevice" x:CompileBindings="False" Command="{Binding SelectDevice}">Select device...</Button>
<Button Grid.Row="2" Grid.Column="3" Name="SelectDevice" x:CompileBindings="False" Command="{Binding SelectDevice}" IsEnabled="False">Select device...</Button>
</Grid>
</StackPanel>
</UserControl>
23 changes: 21 additions & 2 deletions BassBoom/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input;
using Avalonia.Interactivity;
using BassBoom.Basolia;
using BassBoom.Basolia.Devices;
using BassBoom.Basolia.File;
Expand All @@ -28,6 +30,7 @@
using MsBox.Avalonia.Enums;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;

namespace BassBoom.Views;
Expand All @@ -38,14 +41,29 @@ public MainView()
{
InitializeComponent();
DataContext = new BassBoomData(this);
PathToMp3.TextChanged += CheckPath;
}

public void CheckPath(object sender, TextChangedEventArgs e)
{
if (File.Exists(PathToMp3.Text) && (!string.IsNullOrEmpty(((BassBoomData)DataContext).selectedDevice)))
{
PlayButton.IsEnabled = true;
GetDuration.IsEnabled = true;
}
else
{
PlayButton.IsEnabled = false;
GetDuration.IsEnabled = false;
}
}
}

public class BassBoomData
{
private readonly MainView view;
private string selectedDriver = "";
private string selectedDevice = "";
internal string selectedDriver = "";
internal string selectedDevice = "";

public void GetDuration()
{
Expand Down Expand Up @@ -121,6 +139,7 @@ public void SelectDriver()
string answer = selection.SelectionInput;
selectedDriver = answer;
DeviceTools.SetActiveDriver(selectedDriver);
view.SelectDevice.IsEnabled = true;
};
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
selection.ShowDialog(desktop.MainWindow);
Expand Down

0 comments on commit 8196b35

Please sign in to comment.