Skip to content

Commit

Permalink
Fix MediaElement CTD in Windows (#2152)
Browse files Browse the repository at this point in the history
* Fix Null Reference exception when `MediaElement.MetadataArtworkUrl` is not set in XAML.

* Update src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs

Co-authored-by: Shaun Lawrence <[email protected]>

---------

Co-authored-by: Shaun Lawrence <[email protected]>
  • Loading branch information
ne0rrmatrix and bijington authored Aug 29, 2024
1 parent 765d3df commit 803b07b
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ async ValueTask UpdateMetadata()

metadata ??= new(systemMediaControls, MediaElement, Dispatcher);
metadata.SetMetadata(MediaElement);

if (string.IsNullOrEmpty(MediaElement.MetadataArtworkUrl))
{
return;
}
if (!Uri.TryCreate(MediaElement.MetadataArtworkUrl, UriKind.RelativeOrAbsolute, out var metadataArtworkUri))
{
Trace.WriteLine($"{nameof(MediaElement)} unable to update artwork because {nameof(MediaElement.MetadataArtworkUrl)} is not a valid URI");
Expand Down

0 comments on commit 803b07b

Please sign in to comment.