question

JosSantos-0090 avatar image
0 Votes"
JosSantos-0090 asked RobCaplan edited

MediaSession.SetMetadata doesn't work on bluetooth device

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);
 }
dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers