Fixed memory leak issue with song image source not getting disposed. Added playbackbar configuration button.

This commit is contained in:
2025-03-05 22:08:46 -05:00
parent 9fc8791ad1
commit 9890236710
4 changed files with 34 additions and 4 deletions

View File

@@ -2,5 +2,5 @@
public partial class MainViewModel : ViewModelBase public partial class MainViewModel : ViewModelBase
{ {
public string Greeting => "Welcome to Avalonia!"; public static string Greeting => "Welcome to Avalonia!";
} }

View File

@@ -16,7 +16,7 @@ using System.Windows.Input;
namespace Harmonia.UI.ViewModels; namespace Harmonia.UI.ViewModels;
public partial class PlaybackBarViewModel : ViewModelBase public partial class PlaybackBarViewModel : ViewModelBase, IDisposable
{ {
private readonly IAudioPlayer _audioPlayer; private readonly IAudioPlayer _audioPlayer;
private readonly IAudioImageCache _audioImageCache; private readonly IAudioImageCache _audioImageCache;
@@ -52,6 +52,7 @@ public partial class PlaybackBarViewModel : ViewModelBase
} }
private set private set
{ {
_songImageSource?.Dispose();
_songImageSource = value; _songImageSource = value;
OnPropertyChanged(); OnPropertyChanged();
} }
@@ -217,4 +218,10 @@ public partial class PlaybackBarViewModel : ViewModelBase
{ {
_audioPlayer.NextAsync(); _audioPlayer.NextAsync();
} }
public void Dispose()
{
SongImageSource?.Dispose();
GC.SuppressFinalize(this);
}
} }

View File

@@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace Harmonia.UI.ViewModels; namespace Harmonia.UI.ViewModels;
public class PlayingSongInfoViewModel : ViewModelBase public class PlayingSongInfoViewModel : ViewModelBase, IDisposable
{ {
private readonly IAudioPlayer _audioPlayer; private readonly IAudioPlayer _audioPlayer;
private readonly IAudioImageCache _audioImageCache; private readonly IAudioImageCache _audioImageCache;
@@ -41,6 +41,7 @@ public class PlayingSongInfoViewModel : ViewModelBase
} }
private set private set
{ {
_songImageSource?.Dispose();
_songImageSource = value; _songImageSource = value;
OnPropertyChanged(); OnPropertyChanged();
} }
@@ -88,4 +89,10 @@ public class PlayingSongInfoViewModel : ViewModelBase
using MemoryStream stream = new(songPictureInfo.Data); using MemoryStream stream = new(songPictureInfo.Data);
SongImageSource = new(stream); SongImageSource = new(stream);
} }
public void Dispose()
{
SongImageSource?.Dispose();
GC.SuppressFinalize(this);
}
} }

View File

@@ -82,7 +82,7 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<!-- Action Buttons --> <!-- Playback Buttons -->
<Grid Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center"> <Grid Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Button Classes="Flat" Command="{Binding PreviousSongCommand}"> <Button Classes="Flat" Command="{Binding PreviousSongCommand}">
@@ -102,6 +102,22 @@
</Button> </Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
<!-- Action Buttons -->
<Grid Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal">
<Button Classes="Flat">
<PathIcon Classes="FlatButtonIcon" Data="{StaticResource SemiIconSetting}"></PathIcon>
<Button.Flyout>
<MenuFlyout Placement="Top">
<RadioButton Content="Compact" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" GroupName="Density" />
<RadioButton Content="Comfortable" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" GroupName="Density" />
<RadioButton Content="Cozy" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" GroupName="Density" />
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
</Grid>
</Grid> </Grid>
</Border> </Border>
</UserControl> </UserControl>