I'm developing simple music player which have client-server architecture(there is MediaControllerCompat
object in Activity that sends callbacks to MediaSessionCompat
in the MusicService
). I need to change current playlist, when user choose another folder. So, there is MediaBrowserCompat.SubscriptionCallback
object in activity and it has method onChildrenLoaded()
when I get new List of songs. In this method I need to send callback to media session to delete music which was in previous playlist(look at code). It's a problem MediaControllerCompat
is final class and I can't create a subclass where I would add some method to solve my problem.
override fun onChildrenLoaded(parentId: String, children: List<MediaBrowserCompat.MediaItem>) {
super.onChildrenLoaded(parentId, children)
//TODO: check is there some music in current playlist, if there is some music, clear playlist
//add all media
for (mediaItem in children) {
mediaController.addQueueItem(mediaItem.description)
}
//call prepare now so pressing play
mediaController.transportControls.prepare()
}