Added resource classses and a missing converter.
This commit is contained in:
114
Harmonia.WinUI/Views/PlayerView.xaml
Normal file
114
Harmonia.WinUI/Views/PlayerView.xaml
Normal file
@@ -0,0 +1,114 @@
|
||||
<UserControl
|
||||
x:Class="Harmonia.WinUI.Views.PlayerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Harmonia.WinUI.Views"
|
||||
xmlns:vm="using:Harmonia.WinUI.ViewModels"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=PlayerViewModel}"
|
||||
d:DataContext="{d:DesignInstance Type=vm:PlayerViewModel, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="PlayerGrid" TargetType="Grid">
|
||||
<Setter Property="Background" Value="#1a1a1a"/>
|
||||
<Setter Property="Padding" Value="10"/>
|
||||
</Style>
|
||||
<Style x:Key="SongImage" TargetType="Image">
|
||||
<Setter Property="Width" Value="80"/>
|
||||
<Setter Property="Height" Value="80"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid Style="{StaticResource PlayerGrid}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Position Slider -->
|
||||
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" VerticalAlignment="Center" Margin="0 0 0 10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition Width="Auto"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Foreground="#aaaaaa"
|
||||
Text="{Binding Position, Converter={StaticResource SecondsToString}}"
|
||||
FontSize="13"
|
||||
Margin="0 0 6 0"
|
||||
VerticalAlignment="Center"
|
||||
LineHeight="0">
|
||||
</TextBlock>
|
||||
<Slider
|
||||
Name="PositionSlider"
|
||||
Loaded="PositionSlider_Loaded"
|
||||
Grid.Column="1"
|
||||
Value="{Binding CurrentPosition, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
|
||||
Minimum="0"
|
||||
Maximum="{Binding MaxPosition, Mode=OneWay}"
|
||||
ThumbToolTipValueConverter="{StaticResource SecondsToString}"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center" />
|
||||
<TextBlock
|
||||
Grid.Column="2"
|
||||
Foreground="#aaaaaa"
|
||||
Text="{Binding MaxPosition, Converter={StaticResource SecondsToString}}"
|
||||
FontSize="13"
|
||||
Margin="6 0 0 0"
|
||||
VerticalAlignment="Center">
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<!-- Song Info -->
|
||||
<Grid Grid.Row="1" Grid.Column="0" Name="PlayingSongGrid">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Grid Margin="0 0 10 0">
|
||||
<Image Source="{Binding SongImageSource, Mode=OneWay}" Style="{StaticResource SongImage}"></Image>
|
||||
<Canvas Background="#19000000"></Canvas>
|
||||
</Grid>
|
||||
<StackPanel VerticalAlignment="Center">
|
||||
<TextBlock Foreground="#dddddd" FontWeight="SemiBold" FontSize="16" LineHeight="20" Text="{Binding Song, Converter={StaticResource SongTitle}}"></TextBlock>
|
||||
<TextBlock Foreground="#aaaaaa" FontSize="14" LineHeight="20" Text="{Binding Song.Artists, Converter={StaticResource ArtistsToString}}"></TextBlock>
|
||||
<TextBlock Foreground="#aaaaaa" FontSize="14" LineHeight="20" Text="{Binding Song.Album}"></TextBlock>
|
||||
<TextBlock Foreground="#777" FontSize="12" Visibility="{Binding Song, Converter={StaticResource NullVisibility}}" FontWeight="Normal" Opacity="1.0">
|
||||
<Run Text="{Binding Song.FileType}"></Run><Run Text=" - "></Run><Run Text="{Binding Song.BitRate}"></Run><Run Text=" kbps - "></Run><Run Text="{Binding Song.SampleRate}"></Run><Run Text=" Hz"></Run>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Playback Actions -->
|
||||
<Grid Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal" Spacing="16">
|
||||
<Button Style="{StaticResource FlatButton}" Command="{Binding PreviousSongCommand}">
|
||||
<Path Style="{StaticResource FlatButtonPath}" Data="{StaticResource SkipStartFillIcon}"></Path>
|
||||
</Button>
|
||||
<Button Style="{StaticResource FlatButton}" Command="{Binding StopSongCommand}">
|
||||
<Path Style="{StaticResource FlatButtonPath}" Data="{StaticResource StopFillIcon}"></Path>
|
||||
</Button>
|
||||
<Button Style="{StaticResource FlatButton}" Command="{Binding PlaySongCommand}">
|
||||
<Path Style="{StaticResource FlatButtonPath-Large}" Data="{StaticResource PlayFillIcon}"></Path>
|
||||
</Button>
|
||||
<Button Style="{StaticResource FlatButton}" Command="{Binding PauseSongCommand}">
|
||||
<Path Style="{StaticResource FlatButtonPath}" Data="{StaticResource PauseFillIcon}"></Path>
|
||||
</Button>
|
||||
<Button Style="{StaticResource FlatButton}" Command="{Binding NextSongCommand}">
|
||||
<Path Style="{StaticResource FlatButtonPath}" Data="{StaticResource SkipEndFillIcon}"></Path>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
68
Harmonia.WinUI/Views/PlayerView.xaml.cs
Normal file
68
Harmonia.WinUI/Views/PlayerView.xaml.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Harmonia.WinUI.ViewModels;
|
||||
using Microsoft.UI.Input;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
|
||||
namespace Harmonia.WinUI.Views;
|
||||
|
||||
public sealed partial class PlayerView : UserControl
|
||||
{
|
||||
private readonly PlayerViewModel _viewModel;
|
||||
|
||||
public PlayerView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_viewModel = (PlayerViewModel)DataContext;
|
||||
}
|
||||
|
||||
private void PositionSlider_Loaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Slider slider)
|
||||
return;
|
||||
|
||||
PointerEventHandler pointerPressedHandler = new(OnSliderPointerPressed);
|
||||
slider.AddHandler(PointerPressedEvent, pointerPressedHandler, true);
|
||||
|
||||
PointerEventHandler pointerReleasedHandler = new(OnSliderPointerReleased);
|
||||
slider.AddHandler(PointerReleasedEvent, pointerReleasedHandler, true);
|
||||
}
|
||||
|
||||
private void OnSliderPointerPressed(object? sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Slider slider)
|
||||
return;
|
||||
|
||||
PointerPointProperties pointerProperties = e.GetCurrentPoint(slider).Properties;
|
||||
|
||||
if (pointerProperties.IsLeftButtonPressed == false)
|
||||
return;
|
||||
|
||||
_viewModel.IsPositionChangeInProgress = true;
|
||||
}
|
||||
|
||||
private void OnSliderPointerReleased(object? sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Slider slider)
|
||||
return;
|
||||
|
||||
_viewModel.CurrentPosition = slider.Value;
|
||||
_viewModel.IsPositionChangeInProgress = false;
|
||||
}
|
||||
|
||||
private void VolumeSlider_PointerWheelChanged(object? sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Slider slider)
|
||||
return;
|
||||
|
||||
var pointerProperties = e.GetCurrentPoint(slider).Properties;
|
||||
var mouseWheelDelta = pointerProperties.MouseWheelDelta;
|
||||
|
||||
if (mouseWheelDelta == 0)
|
||||
return;
|
||||
|
||||
double delta = mouseWheelDelta > 0 ? .02 : -.02;
|
||||
|
||||
_viewModel.Volume += delta;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user