Skip to content

Commit

Permalink
Enhance media player with artwork display support (#2108)
Browse files Browse the repository at this point in the history
Added a new using directive for Android.Graphics.Drawables in MediaManager.android.cs. Enhanced the StartService method by:
- Adding a null check for PlayerView.
- Setting ArtworkDisplayMode to StyledPlayerView.ArtworkDisplayModeFit.
- Fetching and setting artwork from a URL as DefaultArtwork.
  • Loading branch information
ne0rrmatrix authored Aug 9, 2024
1 parent db26158 commit 1e78f10
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Support.V4.Media;
using Android.Support.V4.Media.Session;
Expand Down Expand Up @@ -659,7 +660,14 @@ async Task StartService(CancellationToken cancellationToken = default)
await checkPermissionsTask.WaitAsync(cancellationToken);
}

ArgumentNullException.ThrowIfNull(PlayerView);
PlayerView.ArtworkDisplayMode = StyledPlayerView.ArtworkDisplayModeFit;
Android.Content.Context? context = Platform.AppContext;
Android.Content.Res.Resources? resources = context.Resources;

var bitmap = await GetBitmapFromUrl(MediaElement.MetadataArtworkUrl, cancellationToken);
PlayerView.DefaultArtwork = new BitmapDrawable(resources, bitmap);

var mediaMetadata = new MediaMetadataCompat.Builder();
mediaMetadata.PutString(MediaMetadataCompat.MetadataKeyArtist, MediaElement.MetadataArtist);
mediaMetadata.PutString(MediaMetadataCompat.MetadataKeyTitle, MediaElement.MetadataTitle);
Expand Down

0 comments on commit 1e78f10

Please sign in to comment.