Skip to content

Commit

Permalink
add - Added progress bar to indicate current duration
Browse files Browse the repository at this point in the history
We've added the progress bar to the GUI version of BassBoom

---

We've added the progress bar that indicates the current position to the GUI version of BassBoom.

---

Type: add
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Aug 30, 2023
1 parent c6eec66 commit 7f21fbd
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 23 deletions.
67 changes: 46 additions & 21 deletions BassBoom/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,50 @@
<vm:MainViewModel />
</Design.DataContext>

<StackPanel>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, 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" x:CompileBindings="False"></TextBox>
</Grid>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto" Margin="15">
<TextBlock Name="DurationLabel" Grid.Row="1" Grid.Column="0">Duration:</TextBlock>
<TextBlock Name="GotDurationLabel" Grid.Row="1" Grid.Column="1"></TextBlock>
</Grid>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto" Margin="15">
<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 PlayAsync}" IsEnabled="False">Play</Button>
<Button Grid.Row="2" Grid.Column="2" Name="PauseButton" x:CompileBindings="False" Command="{Binding Pause}" IsEnabled="False">Pause</Button>
<Button Grid.Row="2" Grid.Column="3" Name="StopButton" x:CompileBindings="False" Command="{Binding Stop}" IsEnabled="False">Stop</Button>
<Button Grid.Row="2" Grid.Column="4" Name="SelectDriver" x:CompileBindings="False" Command="{Binding SelectDriver}" IsEnabled="False">Select driver...</Button>
<Button Grid.Row="2" Grid.Column="5" Name="SelectDevice" x:CompileBindings="False" Command="{Binding SelectDevice}" IsEnabled="False">Select device...</Button>
</Grid>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto" ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto" Margin="15">
<CheckBox Grid.Row="1" Name="DetermineDevice" IsChecked="true">Determine device and driver</CheckBox>
</Grid>
</StackPanel>
<DockPanel
HorizontalAlignment="Stretch">
<StackPanel
DockPanel.Dock="Top"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Grid
RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto"
ColumnDefinitions="Auto, Auto, 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" x:CompileBindings="False"></TextBox>
</Grid>
<Grid
RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto"
ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto"
Margin="15">
<TextBlock Name="DurationLabel" Grid.Row="1" Grid.Column="0">Duration:</TextBlock>
<TextBlock Name="GotDurationLabel" Grid.Row="1" Grid.Column="1"></TextBlock>
</Grid>
<Grid
RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto"
ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto"
Margin="15">
<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 PlayAsync}" IsEnabled="False">Play</Button>
<Button Grid.Row="2" Grid.Column="2" Name="PauseButton" x:CompileBindings="False" Command="{Binding Pause}" IsEnabled="False">Pause</Button>
<Button Grid.Row="2" Grid.Column="3" Name="StopButton" x:CompileBindings="False" Command="{Binding Stop}" IsEnabled="False">Stop</Button>
<Button Grid.Row="2" Grid.Column="4" Name="SelectDriver" x:CompileBindings="False" Command="{Binding SelectDriver}" IsEnabled="False">Select driver...</Button>
<Button Grid.Row="2" Grid.Column="5" Name="SelectDevice" x:CompileBindings="False" Command="{Binding SelectDevice}" IsEnabled="False">Select device...</Button>
</Grid>
<Grid
RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto"
ColumnDefinitions="Auto, Auto, Auto, Auto, Auto, Auto"
Margin="15">
<CheckBox Grid.Row="1" Name="DetermineDevice" IsChecked="true">Determine device and driver</CheckBox>
</Grid>
</StackPanel>
<StackPanel
DockPanel.Dock="Bottom"
Margin="15"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom">
<ProgressBar Name="durationRemain" HorizontalAlignment="Stretch"></ProgressBar>
</StackPanel>
</DockPanel>
</UserControl>
31 changes: 29 additions & 2 deletions BassBoom/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Interactivity;
using Avalonia.Threading;
using BassBoom.Basolia;
using BassBoom.Basolia.Devices;
using BassBoom.Basolia.File;
Expand All @@ -31,6 +32,7 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace BassBoom.Views;
Expand Down Expand Up @@ -70,17 +72,19 @@ private void MakeDeviceDeterministic(object sender, RoutedEventArgs e) =>

public class BassBoomData
{
private readonly MainView view;
internal string selectedDriver;
internal string selectedDevice;
internal bool paused = false;
internal static int duration = 0;
private Thread sliderUpdate = new(UpdateSlider);
private readonly MainView view;

public void GetDuration()
{
try
{
FileTools.OpenFile(view.PathToMp3.Text);
int duration = AudioInfoTools.GetDuration(true);
duration = AudioInfoTools.GetDuration(true);
int durationNoScan = AudioInfoTools.GetDuration(false);
view.GotDurationLabel.Text = $"[{duration} with scan, {durationNoScan} no scan]";
}
Expand Down Expand Up @@ -120,6 +124,8 @@ public async Task PlayAsync()
view.SelectDriver.IsEnabled = false;
view.PauseButton.IsEnabled = true;
view.StopButton.IsEnabled = true;
duration = AudioInfoTools.GetDuration(true);
sliderUpdate.Start(view);
await PlaybackTools.PlayAsync();
}
catch (BasoliaException bex)
Expand Down Expand Up @@ -155,6 +161,7 @@ public void Pause()
try
{
PlaybackTools.Pause();
sliderUpdate = new(UpdateSlider);
}
catch (BasoliaException bex)
{
Expand Down Expand Up @@ -189,6 +196,7 @@ public void Stop()
try
{
PlaybackTools.Stop();
sliderUpdate = new(UpdateSlider);
}
catch (BasoliaException bex)
{
Expand Down Expand Up @@ -318,6 +326,25 @@ internal void HandleDeviceButtons()
view.EnablePlay();
}

private static void UpdateSlider(object obj)
{
SpinWait.SpinUntil(() => PlaybackTools.Playing);
var view = (MainView)obj;
Dispatcher.UIThread.Invoke(() => {
view.durationRemain.Value = 0;
view.GotDurationLabel.Text = $"0/{duration}";
});
while (PlaybackTools.Playing)
{
int position = PlaybackPositioningTools.GetCurrentDuration();
double remaining = 100 * (position / (double)duration);
Dispatcher.UIThread.Invoke(() => {
view.durationRemain.Value = remaining;
view.GotDurationLabel.Text = $"{position}/{duration}";
});
}
}

internal BassBoomData(MainView window)
{
view = window;
Expand Down

0 comments on commit 7f21fbd

Please sign in to comment.