-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<UserControl | ||
x:Class="MusicX.Controls.Blocks.AudioMixesBlock" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:MusicX.Controls.Blocks" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:shaders="clr-namespace:MusicX.Shaders" | ||
xmlns:wpfui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
xmlns:converters="clr-namespace:MusicX.Converters" | ||
Name="Control" | ||
mc:Ignorable="d"> | ||
|
||
<UserControl.Resources> | ||
<converters:InversionBooleanToVisibilityConverter x:Key="InversionBooleanToVisibilityConverter" /> | ||
</UserControl.Resources> | ||
|
||
<Grid MinHeight="500"> | ||
<Rectangle Name="MixRect" | ||
Fill="White" | ||
RadiusY="8" | ||
RadiusX="8"> | ||
<Rectangle.OpacityMask> | ||
<LinearGradientBrush StartPoint="0,0" | ||
EndPoint="0,1"> | ||
<LinearGradientBrush.GradientStops> | ||
<GradientStop Offset="0" | ||
Color="Black" /> | ||
<GradientStop Offset="1" | ||
Color="Transparent" /> | ||
</LinearGradientBrush.GradientStops> | ||
</LinearGradientBrush> | ||
</Rectangle.OpacityMask> | ||
|
||
<Rectangle.Effect> | ||
<shaders:MixNoiseEffect XSize="{Binding ActualWidth, ElementName=MixRect}" | ||
YSize="{Binding ActualHeight, ElementName=MixRect}" /> | ||
</Rectangle.Effect> | ||
</Rectangle> | ||
|
||
<StackPanel HorizontalAlignment="Center" | ||
VerticalAlignment="Center"> | ||
<Button HorizontalAlignment="Center" | ||
VerticalAlignment="Bottom" | ||
BorderThickness="0" | ||
Margin="0 0 0 30" | ||
Click="Button_Click"> | ||
<Button.Style> | ||
<Style TargetType="Button"> | ||
<Setter Property="OverridesDefaultStyle" | ||
Value="True" /> | ||
<Setter Property="SnapsToDevicePixels" Value="True" /> | ||
<Setter Property="Background"> | ||
<Setter.Value> | ||
<SolidColorBrush Color="White" | ||
Opacity="0.7" /> | ||
</Setter.Value> | ||
</Setter> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="Button"> | ||
<Border Padding="12" | ||
Background="{TemplateBinding Background}" | ||
CornerRadius="99" | ||
Name="ContentBorder"> | ||
<ContentPresenter /> | ||
</Border> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
<Style.Triggers> | ||
<Trigger Property="IsMouseOver" | ||
Value="True"> | ||
<Setter Property="Background"> | ||
<Setter.Value> | ||
<SolidColorBrush Color="White" /> | ||
</Setter.Value> | ||
</Setter> | ||
</Trigger> | ||
</Style.Triggers> | ||
</Style> | ||
</Button.Style> | ||
|
||
<wpfui:SymbolIcon Foreground="Black" | ||
FontSize="32"> | ||
<wpfui:SymbolIcon.Style> | ||
<Style TargetType="wpfui:SymbolIcon"> | ||
<Setter Property="Symbol" | ||
Value="Play32" /> | ||
<Style.Triggers> | ||
<DataTrigger Binding="{Binding IsPlaying, ElementName=Control}" Value="True"> | ||
<Setter Property="Symbol" | ||
Value="Pause32" /> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</wpfui:SymbolIcon.Style> | ||
</wpfui:SymbolIcon> | ||
|
||
</Button> | ||
|
||
<!-- the foreground on top of the shader should always be white --> | ||
<TextBlock Foreground="White" | ||
Text="VK mix" | ||
FontSize="70" | ||
TextAlignment="Center" | ||
FontFamily="{StaticResource VKSansDemiBold}" /> | ||
<TextBlock Foreground="White" | ||
Text="Динамический плейлист, который подстраивается под Ваш вкус" | ||
FontSize="17" | ||
FontFamily="{StaticResource VKSansRegular}" /> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using MusicX.Core.Services; | ||
using MusicX.Services; | ||
using MusicX.Services.Player; | ||
using MusicX.Services.Player.Playlists; | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
namespace MusicX.Controls.Blocks; | ||
|
||
public sealed partial class AudioMixesBlock : UserControl | ||
{ | ||
|
||
public bool IsPlaying | ||
{ | ||
get => (bool)GetValue(IsPlayingProperty); | ||
set => SetValue(IsPlayingProperty, value); | ||
} | ||
|
||
public static readonly DependencyProperty IsPlayingProperty = | ||
DependencyProperty.Register("IsPlaying", typeof(bool), typeof(AudioMixesBlock)); | ||
private readonly PlayerService _player; | ||
|
||
public AudioMixesBlock() | ||
{ | ||
InitializeComponent(); | ||
|
||
_player = StaticService.Container.GetRequiredService<PlayerService>(); | ||
|
||
_player.CurrentPlaylistChanged += Player_CurrentPlaylistChanged; | ||
_player.PlayStateChangedEvent += Player_CurrentPlaylistChanged; | ||
Player_CurrentPlaylistChanged(_player, EventArgs.Empty); | ||
} | ||
|
||
private void Player_CurrentPlaylistChanged(object? sender, EventArgs e) | ||
{ | ||
IsPlaying = _player.CurrentPlaylist is MixPlaylist && _player.IsPlaying; | ||
} | ||
|
||
private async void Button_Click(object sender, RoutedEventArgs e) | ||
{ | ||
if (IsPlaying) | ||
{ | ||
_player.Pause(); | ||
return; | ||
} | ||
|
||
if (_player.CurrentPlaylist is MixPlaylist) | ||
{ | ||
_player.Play(); | ||
return; | ||
} | ||
|
||
var data = new MixOptions("common"); | ||
|
||
await _player.PlayAsync(new MixPlaylist(data, StaticService.Container.GetRequiredService<VkService>())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using MusicX.Core.Services; | ||
using MusicX.Shared.Player; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MusicX.Services.Player.Playlists; | ||
|
||
[JsonConverter(typeof(PlaylistJsonConverter<MixPlaylist, MixOptions>))] | ||
public class MixPlaylist(MixOptions data, VkService vkService) : PlaylistBase<MixOptions> | ||
{ | ||
public override bool CanLoad => true; | ||
public override MixOptions Data => data; | ||
|
||
public override async IAsyncEnumerable<PlaylistTrack> LoadAsync() | ||
{ | ||
var tracks = await vkService.GetStreamMixAudios(data.Id, data.Append, options: data.Options); | ||
|
||
foreach (var track in tracks) | ||
{ | ||
yield return track.ToTrack(); | ||
} | ||
|
||
data = data with { Append = data.Append + 1 }; | ||
} | ||
} | ||
|
||
public record MixOptions(string Id, int Append = 0, ImmutableDictionary<string, ImmutableArray<string>>? Options = null) | ||
{ | ||
public override int GetHashCode() | ||
{ | ||
var hashCode = new HashCode(); | ||
|
||
hashCode.Add(Id); | ||
hashCode.Add(Append); | ||
if (Options is not null) | ||
foreach (var (key, values) in Options) | ||
{ | ||
hashCode.Add(key); | ||
foreach (var item in values) | ||
{ | ||
hashCode.Add(item); | ||
} | ||
} | ||
|
||
return hashCode.ToHashCode(); | ||
} | ||
} |