Avalonia:Volume persistence

This commit is contained in:
Royce551 2021-05-09 20:04:58 -05:00
parent 5950a51dac
commit 138b8c9cf7
3 changed files with 38 additions and 2 deletions

View file

@ -35,7 +35,9 @@ namespace FRESHMusicPlayer.Handlers.Configuration
/// <summary>
/// The volume that FMP was set to before closing
/// </summary>
public int Volume { get; set; } = 100;
public float Volume { get; set; } = 1f;
public string FilePath { get; set; }
public double FilePosition { get; set; } = 0;
/// <summary>
/// The last tab FMP was on before closing
/// </summary>

View file

@ -22,13 +22,14 @@ namespace FRESHMusicPlayer.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
public Player Player { get; private set; } = new();
public Player Player { get; private set; }
public Timer ProgressTimer { get; private set; } = new(100);
public Library Library { get; private set; }
public ConfigurationFile Config { get; private set; }
public MainWindowViewModel()
{
Player = new();
StartThings();
var library = new LiteDatabase($"Filename=\"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "database.fdb2")}\";Connection=shared");
Library = new Library(library);
@ -296,11 +297,30 @@ namespace FRESHMusicPlayer.ViewModels
public async void StartThings()
{
Config = await ConfigurationHandler.Read();
Volume = Config?.Volume ?? 1f;
var args = Environment.GetCommandLineArgs();
if (args.Length != 0)
{
Player.Queue.Add(args);
Player.PlayMusic();
Player.CurrentTime.Add(TimeSpan.FromSeconds(Config.FilePosition));
}
else
{
if (!string.IsNullOrEmpty(Config.FilePath))
{
Player.PlayMusic(Config.FilePath);
Player.CurrentTime.Add(TimeSpan.FromSeconds(Config.FilePosition));
}
}
}
public async void CloseThings()
{
Library?.Database.Dispose();
Config.Volume = Volume;
Config.FilePath = Config.FilePath;
if (Player.FileLoaded) Config.FilePosition = Player.CurrentTime.TotalSeconds;
await ConfigurationHandler.Write(Config);
}

View file

@ -20,6 +20,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
@ -672,6 +673,19 @@ namespace FRESHMusicPlayer
case Key.F4:
Topmost = !Topmost;
break;
case Key.F12:
if (WindowStyle == WindowStyle.SingleBorderWindow)
{
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
}
else
{
WindowState = WindowState.Normal;
WindowStyle = WindowStyle.SingleBorderWindow;
}
break;
}
}