mirror of
https://github.com/Royce551/FRESHMusicPlayer.git
synced 2025-01-22 10:51:52 -05:00
push
This commit is contained in:
parent
b9ec1891cd
commit
b88aeb28c1
3 changed files with 100 additions and 25 deletions
|
@ -13,6 +13,10 @@ using System.Collections.ObjectModel;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using ATL.Playlist;
|
||||||
|
|
||||||
namespace FRESHMusicPlayer_Avalonia.ViewModels
|
namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
{
|
{
|
||||||
|
@ -21,9 +25,9 @@ namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
public Player Player { get; private set; } = new();
|
public Player Player { get; private set; } = new();
|
||||||
public Timer ProgressTimer { get; private set; } = new(100);
|
public Timer ProgressTimer { get; private set; } = new(100);
|
||||||
public Library Library { get; private set; }
|
public Library Library { get; private set; }
|
||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
|
|
||||||
var library = new LiteDatabase($"Filename=\"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "database.fdb2")}\";Connection=shared");
|
var library = new LiteDatabase($"Filename=\"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FRESHMusicPlayer", "database.fdb2")}\";Connection=shared");
|
||||||
Library = new Library(library);
|
Library = new Library(library);
|
||||||
InitializeLibrary();
|
InitializeLibrary();
|
||||||
|
@ -160,22 +164,6 @@ namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
Player.NextSong();
|
Player.NextSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClick()
|
|
||||||
{
|
|
||||||
Player.PlayMusic(FilePathToPlay);
|
|
||||||
}
|
|
||||||
public void EnqueueCommand()
|
|
||||||
{
|
|
||||||
Player.Queue.Add(FilePathToPlay);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string? filePathToPlay;
|
|
||||||
public string? FilePathToPlay
|
|
||||||
{
|
|
||||||
get => filePathToPlay;
|
|
||||||
set => this.RaiseAndSetIfChanged(ref filePathToPlay, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimeSpan currentTime;
|
private TimeSpan currentTime;
|
||||||
public TimeSpan CurrentTime
|
public TimeSpan CurrentTime
|
||||||
{
|
{
|
||||||
|
@ -189,7 +177,6 @@ namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this.RaiseAndSetIfChanged(ref currentTime, value);
|
this.RaiseAndSetIfChanged(ref currentTime, value);
|
||||||
//CurrentTimeSeconds = CurrentTime.TotalSeconds;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +195,7 @@ namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
Debug.WriteLine($"CurrentTimeSeconds set. Value is {value}");
|
Debug.WriteLine($"CurrentTimeSeconds set. Value is {value}");
|
||||||
if (TimeSpan.FromSeconds(value) >= TotalTime) return;
|
if (TimeSpan.FromSeconds(value) >= TotalTime) return;
|
||||||
Player.CurrentTime = TimeSpan.FromSeconds(value);
|
Player.CurrentTime = TimeSpan.FromSeconds(value);
|
||||||
//ProgressTick();
|
ProgressTick();
|
||||||
this.RaiseAndSetIfChanged(ref currentTimeSeconds, value);
|
this.RaiseAndSetIfChanged(ref currentTimeSeconds, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,7 +211,6 @@ namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this.RaiseAndSetIfChanged(ref totalTime, value);
|
this.RaiseAndSetIfChanged(ref totalTime, value);
|
||||||
//TotalTimeSeconds = TotalTime.TotalSeconds;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private double totalTimeSeconds;
|
private double totalTimeSeconds;
|
||||||
|
@ -314,6 +300,94 @@ namespace FRESHMusicPlayer_Avalonia.ViewModels
|
||||||
Player.PlayMusic();
|
Player.PlayMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string filePathOrURL;
|
||||||
|
public string FilePathOrURL
|
||||||
|
{
|
||||||
|
get => filePathOrURL;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref filePathOrURL, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string> acceptableFilePaths = "*.wav;*.aiff;*.mp3;*.wma;*.3g2;*.3gp;*.3gp2;*.3gpp;*.asf;*.wmv;*.aac;*.adts;*.avi;*.m4a;*.m4a;*.m4v;*.mov;*.mp4;*.sami;*.smi;*.flac".Split(';').ToList();
|
||||||
|
// ripped directly from fmp-wpf 'cause i'm lazy
|
||||||
|
public async void BrowseTracksCommand()
|
||||||
|
{
|
||||||
|
var dialog = new OpenFileDialog()
|
||||||
|
{
|
||||||
|
Filters = new List<FileDialogFilter>
|
||||||
|
{
|
||||||
|
new FileDialogFilter()
|
||||||
|
{
|
||||||
|
Name = "Audio Files",
|
||||||
|
Extensions = acceptableFilePaths
|
||||||
|
},
|
||||||
|
new FileDialogFilter()
|
||||||
|
{
|
||||||
|
Name = "Other",
|
||||||
|
Extensions = new List<string>(){"*"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
{
|
||||||
|
var files = await dialog.ShowAsync(desktop.MainWindow);
|
||||||
|
await Task.Run(() => Library.Import(files));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public async void BrowsePlaylistFilesCommand()
|
||||||
|
{
|
||||||
|
var dialog = new OpenFileDialog()
|
||||||
|
{
|
||||||
|
Filters = new List<FileDialogFilter>
|
||||||
|
{
|
||||||
|
new FileDialogFilter()
|
||||||
|
{
|
||||||
|
Name = "Playlist Files",
|
||||||
|
Extensions = new(){ "*.xspf", "*.asx", "*.wvx", "*.b4s", "*.m3u", "*.m3u8", "*.pls", "*.smil", "*.smi", "*.zpl"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
{
|
||||||
|
var files = await dialog.ShowAsync(desktop.MainWindow);
|
||||||
|
IPlaylistIO reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(files[0]);
|
||||||
|
foreach (string s in reader.FilePaths)
|
||||||
|
{
|
||||||
|
if (!File.Exists(s))
|
||||||
|
continue; // TODO: show something to the user
|
||||||
|
}
|
||||||
|
Player.Queue.Add(reader.FilePaths.ToArray());
|
||||||
|
await Task.Run(() => Library.Import(reader.FilePaths.ToArray()));
|
||||||
|
Player.PlayMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async void BrowseFoldersCommand()
|
||||||
|
{
|
||||||
|
var dialog = new OpenFolderDialog()
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
if (Avalonia.Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
{
|
||||||
|
await dialog.ShowAsync(desktop.MainWindow);
|
||||||
|
var paths = Directory.EnumerateFiles(dialog.Directory, "*", SearchOption.AllDirectories)
|
||||||
|
.Where(name => name.EndsWith(".mp3")
|
||||||
|
|| name.EndsWith(".wav") || name.EndsWith(".m4a") || name.EndsWith(".ogg")
|
||||||
|
|| name.EndsWith(".flac") || name.EndsWith(".aiff")
|
||||||
|
|| name.EndsWith(".wma")
|
||||||
|
|| name.EndsWith(".aac")).ToArray();
|
||||||
|
Player.Queue.Add(paths);
|
||||||
|
await Task.Run(() => Library.Import(paths));
|
||||||
|
Player.PlayMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void ImportFilePathCommand()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(FilePathOrURL)) return;
|
||||||
|
Player.Queue.Add(FilePathOrURL);
|
||||||
|
Library.Import(FilePathOrURL);
|
||||||
|
Player.PlayMusic();
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,12 +162,12 @@
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button Grid.Row="0" Grid.ColumnSpan="2" Content="Browse for tracks"/>
|
<Button Grid.Row="0" Grid.ColumnSpan="2" Command="{Binding BrowseTracksCommand}" Content="Browse for tracks"/>
|
||||||
<Button Grid.Row="1" Grid.ColumnSpan="2" Content="Browse for playlist files"/>
|
<Button Grid.Row="1" Grid.ColumnSpan="2" Command="{Binding BrowsePlaylistFilesCommand}" Content="Browse for playlist files"/>
|
||||||
<Button Grid.Row="2" Grid.ColumnSpan="2" Content="Browse for folders"/>
|
<Button Grid.Row="2" Grid.ColumnSpan="2" Command="{Binding BrowseFoldersCommand}" Content="Browse for folders"/>
|
||||||
<TextBlock Grid.Row="3" Grid.ColumnSpan="2" Text="File path or URL"/>
|
<TextBlock Grid.Row="3" Grid.ColumnSpan="2" Text="File path or URL"/>
|
||||||
<TextBox Grid.Row="4" Grid.Column="0"/>
|
<TextBox Grid.Row="4" Grid.Column="0" Text="{Binding FilePathOrURL}"/>
|
||||||
<Button Grid.Row="4" Grid.Column="1" Content="Import"/>
|
<Button Grid.Row="4" Grid.Column="1" Command="{Binding ImportFilePathCommand}" Content="Import"/>
|
||||||
<TextBlock Grid.Row="5" Grid.ColumnSpan="2" Text="You can also drag and drop to this page."/>
|
<TextBlock Grid.Row="5" Grid.ColumnSpan="2" Text="You can also drag and drop to this page."/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace FRESHMusicPlayer_Avalonia.Views
|
||||||
this.AttachDevTools();
|
this.AttachDevTools();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
|
Loading…
Reference in a new issue