too many to add
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
Visibility="{x:Bind ViewModel.Visible, Mode=OneWay}">
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">
|
||||
<UserControl.Resources>
|
||||
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
|
||||
|
||||
@@ -1,39 +1,43 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
[NotificationHandler(nameof(PlaybackButtonType))]
|
||||
public partial class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory,
|
||||
PlaybackButtonType buttonType,
|
||||
PlaybackButtonType playbackButtonType,
|
||||
Guid guid = default,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) :
|
||||
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command),
|
||||
IInitialization,
|
||||
INotificationHandler<Changed<PlaybackInformation>>
|
||||
IInitialization
|
||||
{
|
||||
public Task Handle(Changed<PlaybackInformation> notification,
|
||||
[ObservableProperty]
|
||||
private PlaybackButtonType playbackButtonType = playbackButtonType;
|
||||
|
||||
public Task Handle(Changed<MediaControllerPlaybackStatus> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is PlaybackInformation information)
|
||||
if (notification.Value is MediaControllerPlaybackStatus information)
|
||||
{
|
||||
switch (buttonType)
|
||||
{
|
||||
case PlaybackButtonType.Play:
|
||||
Visible = information.Status is PlaybackStatus.Paused;
|
||||
break;
|
||||
case PlaybackButtonType.Pause:
|
||||
Visible = information.Status is PlaybackStatus.Playing;
|
||||
break;
|
||||
}
|
||||
//switch (buttonType)
|
||||
//{
|
||||
// case PlaybackButtonType.Play:
|
||||
// Visible = information.Status is PlaybackStatus.Paused;
|
||||
// break;
|
||||
// case PlaybackButtonType.Pause:
|
||||
// Visible = information.Status is PlaybackStatus.Playing;
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override async Task InitializeAsync() =>
|
||||
await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
||||
//public override async Task InitializeAsync() =>
|
||||
// await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
using Windows.Media.Control;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Media.Control;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaController :
|
||||
INotificationHandler<Play>,
|
||||
INotificationHandler<Pause>,
|
||||
INotificationHandler<Request<PlaybackInformation>>,
|
||||
INotificationHandler<Request<MediaControllerPlaybackStatus>>,
|
||||
INotificationHandler<Request<MediaInformation>>,
|
||||
IDisposable
|
||||
{
|
||||
private readonly AsyncLock asyncLock = new();
|
||||
private readonly IDisposer disposer;
|
||||
private readonly IMediator mediator;
|
||||
private readonly GlobalSystemMediaTransportControlsSession session;
|
||||
private GlobalSystemMediaTransportControlsSession? session;
|
||||
|
||||
private GlobalSystemMediaTransportControlsSessionPlaybackStatus playbackStatus;
|
||||
|
||||
public MediaController(IMediator mediator,
|
||||
IDisposer disposer,
|
||||
@@ -31,6 +38,8 @@ public class MediaController :
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
session = null;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
disposer.Dispose(this);
|
||||
}
|
||||
@@ -49,7 +58,7 @@ public class MediaController :
|
||||
await UpdateMediaPlaybackPropertiesAsync();
|
||||
}
|
||||
|
||||
public async Task Handle(Request<PlaybackInformation> args,
|
||||
public async Task Handle(Request<MediaControllerPlaybackStatus> args,
|
||||
CancellationToken cancellationToken) => await UpdateMediaPlaybackPropertiesAsync();
|
||||
|
||||
public async Task Handle(Request<MediaInformation> args,
|
||||
@@ -68,9 +77,14 @@ public class MediaController :
|
||||
try
|
||||
{
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo = session.GetPlaybackInfo();
|
||||
await mediator.PublishAsync(new Changed<PlaybackInformation>(
|
||||
new PlaybackInformation((PlaybackStatus)playbackInfo.PlaybackStatus)));
|
||||
|
||||
if (playbackInfo.PlaybackStatus != playbackStatus)
|
||||
{
|
||||
playbackStatus = playbackInfo.PlaybackStatus;
|
||||
await mediator.PublishAsync(new Changed<MediaControllerPlaybackStatus>(
|
||||
new MediaControllerPlaybackStatus((PlaybackStatus)playbackStatus)));
|
||||
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -81,20 +95,31 @@ public class MediaController :
|
||||
|
||||
private async Task UpdateMediaPropertiesAsync()
|
||||
{
|
||||
using (await asyncLock)
|
||||
if (session is not null)
|
||||
{
|
||||
try
|
||||
using (await asyncLock)
|
||||
{
|
||||
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
||||
await session.TryGetMediaPropertiesAsync();
|
||||
try
|
||||
{
|
||||
|
||||
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
||||
mediaProperties.Artist)));
|
||||
//
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
//InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
|
||||
|
||||
//// Copy the image stream to the random access stream
|
||||
//await d.AsStream().CopyToAsync(randomAccessStream.AsStreamForWrite());
|
||||
|
||||
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
||||
await session.TryGetMediaPropertiesAsync();
|
||||
|
||||
IRandomAccessStreamWithContentType randomAccessStream = await mediaProperties.Thumbnail.OpenReadAsync();
|
||||
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
||||
mediaProperties.Artist, randomAccessStream.AsStream())));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaControllerManager(IMediator mediator,
|
||||
IFactory<GlobalSystemMediaTransportControlsSession, MediaController> factory,
|
||||
IDispatcher dispatcher,
|
||||
IDisposer disposer) :
|
||||
IFactory<GlobalSystemMediaTransportControlsSession, MediaController> factory) :
|
||||
IInitializer
|
||||
{
|
||||
|
||||
private readonly AsyncLock asyncLock = new();
|
||||
private readonly List<KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>> cache = [];
|
||||
private GlobalSystemMediaTransportControlsSessionManager? mediaTransportControlsSessionManager;
|
||||
@@ -16,7 +15,7 @@ public class MediaControllerManager(IMediator mediator,
|
||||
{
|
||||
mediaTransportControlsSessionManager = await GlobalSystemMediaTransportControlsSessionManager.RequestAsync();
|
||||
mediaTransportControlsSessionManager.SessionsChanged += OnSessionsChanged;
|
||||
|
||||
|
||||
IReadOnlyList<GlobalSystemMediaTransportControlsSession> sessions =
|
||||
mediaTransportControlsSessionManager.GetSessions();
|
||||
|
||||
@@ -31,7 +30,8 @@ public class MediaControllerManager(IMediator mediator,
|
||||
if (factory.Create(session) is MediaController mediaController)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<MediaController>(mediaController));
|
||||
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session, mediaController));
|
||||
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session,
|
||||
mediaController));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public record PlaybackInformation(PlaybackStatus Status) :
|
||||
public record MediaControllerPlaybackStatus(PlaybackStatus Status) :
|
||||
INotification;
|
||||
@@ -0,0 +1,31 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaControllerPlaybackStatusHandler(IMediator mediator,
|
||||
IServiceFactory factory) :
|
||||
INotificationHandler<Changed<MediaControllerPlaybackStatus>>
|
||||
{
|
||||
public async Task Handle(Changed<MediaControllerPlaybackStatus> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is MediaControllerPlaybackStatus mediaControllerPlaybackInformation)
|
||||
{
|
||||
if (mediaControllerPlaybackInformation.Status is PlaybackStatus.Playing)
|
||||
{
|
||||
await mediator.PublishAsync(new Replaced<WidgetComponentViewModel>(2, factory.Create<MediaButtonViewModel>(
|
||||
PlaybackButtonType.Pause, "Pause", "\uE769",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Pause>()))), nameof(MediaControllerViewModel),
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
if (mediaControllerPlaybackInformation.Status is PlaybackStatus.Paused)
|
||||
{
|
||||
await mediator.PublishAsync(new Replaced<WidgetComponentViewModel>(2, factory.Create<MediaButtonViewModel>(
|
||||
PlaybackButtonType.Pause, "Play", "\uE768",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Play>()))), nameof(MediaControllerViewModel),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@
|
||||
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
<Grid Width="400" Background="red">
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<Grid>
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Center"
|
||||
ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}"
|
||||
HorizontalAlignment="Right"
|
||||
HorizontalContentAlignment="Right"
|
||||
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
||||
ItemsSource="{Binding}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
[NotificationHandler(nameof(MediaControllerViewModel))]
|
||||
public class MediaControllerViewModel :
|
||||
ObservableCollectionViewModel<WidgetComponentViewModel>,
|
||||
ITemplatedViewModel
|
||||
@@ -15,19 +16,15 @@ public class MediaControllerViewModel :
|
||||
|
||||
Add<MediaInformationViewModel>();
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Previous,
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Previous,
|
||||
"Previous", "\uEB9E",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Previous>()));
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Play,
|
||||
"Play", "\uE768",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Play>()));
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Pause,
|
||||
"Pause", "\uE769",
|
||||
"Pause", "\uE769",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Pause>()));
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Forward,
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Forward,
|
||||
"Forward", "\uEB9D",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Forward>()));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Hyperbar.Widget;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Windows.Media.Control;
|
||||
|
||||
@@ -22,6 +21,7 @@ public class MediaControllerWidget :
|
||||
.AddHandler<MediaControllerHandler>()
|
||||
.AddTransient<IFactory<MediaController, MediaControllerViewModel?>, MediaControllerViewModelFactory>()
|
||||
.AddCache<MediaController, MediaControllerViewModel>()
|
||||
.AddHandler<MediaControllerPlaybackStatusHandler>()
|
||||
.AddContentTemplate<MediaControllerViewModel, MediaControllerView>()
|
||||
.AddContentTemplate<MediaInformationViewModel, MediaInformationView>()
|
||||
.AddContentTemplate<MediaButtonViewModel, MediaButtonView>();
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerWidgetView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<FlipView
|
||||
x:Name="FlipView"
|
||||
Width="400"
|
||||
Background="Transparent"
|
||||
ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}"
|
||||
Width="360"
|
||||
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
||||
ItemsSource="{Binding}" />
|
||||
</UserControl>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public record MediaInformation(string Title, string Description);
|
||||
public record MediaInformation(string Title,
|
||||
string Description,
|
||||
Stream ThumbnailSource);
|
||||
|
||||
|
||||
|
||||
@@ -4,27 +4,35 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">
|
||||
<Grid>
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<Grid Width="216">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="40" />
|
||||
<ColumnDefinition Width="8" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
Grid.Column="0"
|
||||
Width="40"
|
||||
Height="40"
|
||||
Background="Red" />
|
||||
Height="40">
|
||||
<Image Source="{Binding ThumbnailSource, Converter={windows:StreamToImageSourceConverter}}" />
|
||||
</Border>
|
||||
<StackPanel Grid.Column="2">
|
||||
<TextBlock Style="{ThemeResource BaseTextBlockStyle}" Text="{Binding Title}" />
|
||||
<TextBlock
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Text="{x:Bind ViewModel.Title, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
<TextBlock
|
||||
Opacity="0.7"
|
||||
Style="{ThemeResource CaptionTextBlockStyle}"
|
||||
Text="{Binding Description}" />
|
||||
Text="{x:Bind ViewModel.Description, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<interactions:EventTriggerBehavior EventName="Loaded">
|
||||
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
|
||||
<interactions:InvokeCommandAction Command="{x:Bind ViewModel.Initialize}" />
|
||||
</interactions:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</StackPanel>
|
||||
|
||||
@@ -8,4 +8,6 @@ public sealed partial class MediaInformationView :
|
||||
{
|
||||
public MediaInformationView() =>
|
||||
this.InitializeComponent(ref _contentLoaded);
|
||||
|
||||
private MediaInformationViewModel ViewModel => (MediaInformationViewModel)DataContext;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Hyperbar.Widget;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
@@ -14,6 +14,9 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
[ObservableProperty]
|
||||
private string? description;
|
||||
|
||||
[ObservableProperty]
|
||||
private Stream? thumbnailSource;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? title;
|
||||
|
||||
@@ -24,6 +27,7 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
{
|
||||
Title = value.Title;
|
||||
Description = value.Description;
|
||||
ThumbnailSource = value.ThumbnailSource;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
Reference in New Issue
Block a user