Initial commit
This commit is contained in:
9
TechMedia.Interface.Wpf/App.xaml
Normal file
9
TechMedia.Interface.Wpf/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="TechMedia.Interface.Wpf.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:TechMedia.Interface.Wpf"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
17
TechMedia.Interface.Wpf/App.xaml.cs
Normal file
17
TechMedia.Interface.Wpf/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace TechMedia.Interface.Wpf
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
10
TechMedia.Interface.Wpf/AssemblyInfo.cs
Normal file
10
TechMedia.Interface.Wpf/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
58
TechMedia.Interface.Wpf/MainWindow.xaml
Normal file
58
TechMedia.Interface.Wpf/MainWindow.xaml
Normal file
@@ -0,0 +1,58 @@
|
||||
<Window x:Class="TechMedia.Interface.Wpf.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:TechMedia.Interface.Wpf"
|
||||
mc:Ignorable="d"
|
||||
Title="TechMedia" Height="450" Width="800"
|
||||
Padding="3">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label>Folder:</Label>
|
||||
<TextBox Name="FilenameTextBox" Grid.Row="0" Grid.Column="1" Margin="6">D:\users\mikah\music</TextBox>
|
||||
<Button Name="LoadButton" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="6" Click="LoadButton_Click">Load Folder</Button>
|
||||
<Button Name="PlayButton"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Margin="6"
|
||||
Click="PlayButtonClicked">
|
||||
Play
|
||||
</Button>
|
||||
<Button Grid.Row="2" Grid.Column="1" Margin="6" Click="Button_Click">Stop</Button>
|
||||
<Button Name="ShuffleButton" Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Margin="6" Click="ShuffleButton_Click">Shuffle</Button>
|
||||
<DataGrid Name="TrackDataGrid" Grid.Row="5" Grid.ColumnSpan="2" Grid.Column="0" ItemsSource="{Binding}">
|
||||
</DataGrid>
|
||||
<ProgressBar Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Height="20" Name="LoadProgressBar">
|
||||
</ProgressBar>
|
||||
<TextBlock Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Name="LoadingTextBlock">Waiting for tracks</TextBlock>
|
||||
<Image Grid.Row="7" Grid.RowSpan="2" Grid.Column="0"></Image>
|
||||
<Label Grid.Row="7" Grid.Column="1" Name="TitleLabel">Track Name</Label>
|
||||
<Label Grid.Row="8" Grid.Column="1" Name="AlbumLabel">Track Album</Label>
|
||||
<Label Grid.Row="9" Grid.Column="1" Name="TimeLabel">0:00/0:00</Label>
|
||||
<ProgressBar Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="2" Height="10" Name="PlaybackProgressBar" Foreground="#FF066EB0">
|
||||
</ProgressBar>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="2">Request filename:</Label>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" Margin="6" Name="RequestFilenameTextBox"></TextBox>
|
||||
<Button Grid.Row="2" Grid.Column="2" Margin="6" Click="Button_Click_1">Submit Request</Button>
|
||||
<Label Grid.Row="3" Grid.Column="2" Name="RequestStatusLabel">No requests submitted</Label>
|
||||
</Grid>
|
||||
</Window>
|
||||
98
TechMedia.Interface.Wpf/MainWindow.xaml.cs
Normal file
98
TechMedia.Interface.Wpf/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using TechMedia.Backend.Vlc;
|
||||
using TechMedia.Core;
|
||||
using TechMedia.Core.Model;
|
||||
|
||||
namespace TechMedia.Interface.Wpf
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public Track CurrentTrack { get; set; } = new();
|
||||
private readonly ITechMediaCore _player = new TechMediaCore(new VlcAudioBackend());
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = CurrentTrack;
|
||||
_player.RegisterPlaylistChangeListener(new Progress<List<Track>>(newPlaylist => TrackDataGrid.DataContext = newPlaylist));
|
||||
}
|
||||
|
||||
private static string FormatMillis(int millis)
|
||||
{
|
||||
var seconds = millis / 1000;
|
||||
return $"{seconds / 60}:{(seconds % 60).ToString().PadLeft(2, '0')}";
|
||||
}
|
||||
|
||||
private void PlayButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
var trackUpdater = new Progress<Track>(track =>
|
||||
{
|
||||
CurrentTrack = track;
|
||||
TitleLabel.Content = track.Title ?? "No title available";
|
||||
AlbumLabel.Content = track.Album ?? "No album available";
|
||||
});
|
||||
var progressUpdater = new Progress<float>(p =>
|
||||
{
|
||||
PlaybackProgressBar.Value = p;
|
||||
TimeLabel.Content = $"{FormatMillis((int)(CurrentTrack.Duration * p))}/{FormatMillis((int)(CurrentTrack.Duration))}";
|
||||
});
|
||||
PlaybackProgressBar.Maximum = 1.0f;
|
||||
_player.StartPlaylistPlayback(trackUpdater, progressUpdater);
|
||||
}
|
||||
|
||||
private async void LoadButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var allFiles = Directory.EnumerateFiles(FilenameTextBox.Text, "*.*", SearchOption.AllDirectories).ToList();
|
||||
LoadProgressBar.Maximum = allFiles.Count;
|
||||
IProgress<int> progress = new Progress<int>(state =>
|
||||
{
|
||||
LoadProgressBar.Value = state;
|
||||
LoadingTextBlock.Text = $"Loading... {state}/{allFiles.Count}";
|
||||
});
|
||||
var loadedCount = await _player.LoadFiles(allFiles, progress);
|
||||
LoadingTextBlock.Text = $"Tracks loaded: {loadedCount}";
|
||||
LoadProgressBar.Value = LoadProgressBar.Maximum;
|
||||
MessageBox.Show($"Loaded {loadedCount} tracks");
|
||||
TrackDataGrid.DataContext = _player.GetCurrentPlaylist();
|
||||
}
|
||||
|
||||
private void ShuffleButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TrackDataGrid.DataContext = _player.ShuffleCurrentPlaylist();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_player.Stop();
|
||||
}
|
||||
|
||||
private void Button_Click_1(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var requestedTrack = _player.SubmitRequest(RequestFilenameTextBox.Text);
|
||||
if (requestedTrack != null)
|
||||
{
|
||||
RequestStatusLabel.Content = $"{requestedTrack.Title} added to queue";
|
||||
}
|
||||
else
|
||||
{
|
||||
RequestStatusLabel.Content = "File not found in playlist";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj
Normal file
15
TechMedia.Interface.Wpf/TechMedia.Interface.Wpf.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TechMedia.Backend.Vlc\TechMedia.Backend.Vlc.csproj" />
|
||||
<ProjectReference Include="..\TechMedia.Core\TechMedia.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user