Search code examples
androidandroid-automediabrowserservicecompat

How can I change Media items in Android MediaBrowserServiceCompat


I am making an Android Auto based media player. I really have one page of media that can be played, but sometimes the titles of these items change. Lets say the first item says 'news of the hour for 12pm' and then it changes to 'news of the hour for 1p'.

onGetRoot is called, then I populate my media items in onLoadChildren. I make ArrayList at the time of launch, but these items can change.

How do I programmatically alter the MediaItem objects already loaded into the UI?


Solution

  • This is exactly what the notifyChildrenChanged() method on MediaBrowserServiceCompat is for - calling that will invalidate the data returned by onLoadChildren and cause the system to call onLoadChildren again to retrieve your updated data.