Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override MauiMediaElement CreatePlatformView()
Dispatcher.GetForCurrentThread() ?? throw new InvalidOperationException($"{nameof(IDispatcher)} cannot be null"));

(_, playerViewController) = mediaManager.CreatePlatformView();

return new(playerViewController, VirtualView);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using AVKit;
using CommunityToolkit.Maui.Views;
using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Controls.Handlers.Items;
using Microsoft.Maui.Handlers;
using UIKit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Numerics;
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Views;
using Microsoft.Extensions.Logging;
Expand All @@ -8,7 +9,6 @@
using Windows.Media.Playback;
using Windows.Storage;
using Windows.System.Display;
using Page = Microsoft.Maui.Controls.Page;
using ParentWindow = CommunityToolkit.Maui.Extensions.PageExtensions.ParentWindow;
using WindowsMediaElement = Windows.Media.Playback.MediaPlayer;
using WinMediaSource = Windows.Media.Core.MediaSource;
Expand Down Expand Up @@ -160,12 +160,12 @@ protected virtual partial void PlatformUpdateSpeed()
Player.MediaPlayer.PlaybackRate = MediaElement.Speed;

// Only trigger once when going to the paused state
if (AreFloatingPointNumbersEqual(MediaElement.Speed, 0) && previousSpeed > 0)
if (IsZero<double>(MediaElement.Speed) && previousSpeed > 0)
{
Player.MediaPlayer.Pause();
}
// Only trigger once when we move from the paused state
else if (MediaElement.Speed > 0 && AreFloatingPointNumbersEqual(previousSpeed, 0))
else if (MediaElement.Speed > 0 && IsZero<double>(previousSpeed))
{
MediaElement.Play();
}
Expand Down Expand Up @@ -345,6 +345,11 @@ protected virtual void Dispose(bool disposing)
}
}

static bool IsZero<TValue>(TValue numericValue) where TValue : INumber<TValue>
{
return TValue.IsZero(numericValue);
}

async ValueTask UpdateMetadata()
{
if (systemMediaControls is null || Player is null)
Expand Down Expand Up @@ -485,7 +490,7 @@ void OnPlaybackSessionPlaybackStateChanged(MediaPlaybackSession sender, object a
};

MediaElement?.CurrentStateChanged(newState);
if (sender.PlaybackState == MediaPlaybackState.Playing && AreFloatingPointNumbersEqual(sender.PlaybackRate, 0))
if (sender.PlaybackState == MediaPlaybackState.Playing && IsZero<double>(sender.PlaybackRate))
{
Dispatcher.Dispatch(() =>
{
Expand Down