I am developing an application in Xamarin Android to play music in streaming. When setting the metadata, they are updated and displayed correctly in the mobile notification, but when I connect it to a device via bluetooth such as the car, the metadata is not updated. Could someone tell me why?
The code where I create the MediaSession and update the metadata is as follows.
private void InitMediaSession()
{
MediaSession = new MediaSessionCompat(ApplicationContext, ApplicationContext.PackageName);
Intent intent = PackageManager?.GetLaunchIntentForPackage(PackageName);
PendingIntent pendingIntent = PendingIntent.GetActivity(ApplicationContext, 0, intent, PendingIntentFlags.UpdateCurrent);
MediaSession.SetSessionActivity(pendingIntent);
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
MediaSession.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls);
}
MediaSession.Active = true;
SessionToken = MediaSession.SessionToken;
}
private void UpdateMetadata(string title, string artist)
{
var metadataBuilder = new MediaMetadataCompat.Builder();
metadataBuilder.PutString(MediaMetadata.MetadataKeyTitle, title)
.PutString(MediaMetadata.MetadataKeyArtist, artist);
var metadata = metadataBuilder.Build();
MediaSession.SetMetadata(metadata);
}