.Net MAUI - Android TV - Displaying Now Playing card
first of all, I know that Maui not supporting android TV now, however, the code I need for this is included in.NET MAUI from Xamarin Forms and A[ndroid.Media.Session][1].
I just can't apply the code correctly or I'm missing something from these documentations
- Display a Now Playing card
- Implement a media session
- MediaSession.NET API browser/Android.Media.Session
Now here is the code I wrote based on these documentations
public static class Declarations
{
public static MediaSession mediaSession = new MediaSession(MainActivity.ActivityCurrent, "myappname") { Active=false};
}
public void RegisterNotificationPlayingNowTV()
{
global::Android.Content.Intent intent = new global::Android.Content.Intent(this, typeof(MainActivity));
const int pendingIntentId = 2;
PendingIntent pendingIntent = PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.Immutable);
Declarations.mediaSession.SetCallback(null);
Declarations.mediaSession.SetFlags(MediaSessionFlags.HandlesMediaButtons);
Declarations.mediaSession.SetFlags(MediaSessionFlags.HandlesTransportControls);
Declarations.mediaSession.SetMetadata(new MediaMetadata.Builder()
.PutString(MediaMetadata.MetadataKeyArtist, "any name")
.PutString(MediaMetadata.MetadataKeyAlbum, "any album")
.PutString(MediaMetadata.MetadataKeyTitle, "any title")
.Build());
Declarations.mediaSession.SetSessionActivity(pendingIntent);
Declarations.mediaSession.Active = true;
}
The code doesn't trigger any error, but still, no card is displed when I call that code.
I took a long shot with this project and I'm not ready yet to quit.
I'm planning to add all the fixes I applied for my MAUI Android TV to be approved by Google Play in one article since Microsoft stated that .Net Maui not supporting Android TV, however, it has all the libraries needed and I was able to overcome most of the issues.