Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit f3a4251

Browse files
authored
Fix random crash on iOS when switching source (#1899)
1 parent 14c7ab4 commit f3a4251

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/MediaElement/iOS/MediaElementRenderer.ios.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,15 @@ TimeSpan Position
196196
{
197197
get
198198
{
199-
if (avPlayerViewController?.Player?.CurrentTime.IsInvalid ?? true)
199+
if (avPlayerViewController.Player?.CurrentItem == null)
200200
return TimeSpan.Zero;
201201

202-
return TimeSpan.FromSeconds(avPlayerViewController.Player.CurrentTime.Seconds);
202+
var currentTime = avPlayerViewController.Player.CurrentTime;
203+
204+
if (double.IsNaN(currentTime.Seconds) || currentTime.IsIndefinite)
205+
return TimeSpan.Zero;
206+
207+
return TimeSpan.FromSeconds(currentTime.Seconds);
203208
}
204209
}
205210

0 commit comments

Comments
 (0)