Reputation: 3195
I made my first audio app (music player) using client/server architecture: https://developer.android.com/guide/topics/media-apps/audio-app/building-a-mediabrowserservice.html
It works ok. I tested only with one song - I set a source (Uri) for MediaPlayer
instance in my MediaService
class using hardcoded way just for a test.
It plays this song normally, displays information about it in notification and lockscreen, play/pause button also works ok.
But now I need to make a playlist.
What is the best practice to do it?
Is it ok just to make an instance List
of some MyAudio
class, set fields like title, artist, source (and so on) of all MyAudio
instances (when user picked some folder from his device storage) and then just use them in onSkipToNext
, onSkipToPrevious
of MediaSessionCallback
, onCompletion
of 'MediaPlayer'.
There is a line List<MediaItem> mediaItems = new ArrayList<>();
in onLoadChildren()
method from that client/server architecture example.
But do I need this? Or these methods (with getRoot()
) just needed to give other apps an opportunity to use my MediaService to get list of music/playlist.
If I don't this that I can don't care about these methods?
Upvotes: 0
Views: 447
Reputation: 199880
The whole point of using MediaItem
s is that it gives you a pre-built mechanism for passing a list of objects available to play between your MediaBrowserServiceCompat
and your UI as explained in this MediaBrowserService blog post - if you build your own MyAudio
class, it is much more difficult to pass that between the two in any clean way.
Of course, if you only have a fixed playlist of what is currently being played (and not a list of items to select from), you're probably better suited to use the queue APIs in MediaSession
. Namely, setQueue() and getQueue().
Upvotes: 1