I'm new to android development. I want to create a music player that functions in a client-server fashion. I'm trying to create the server part for now. I found out that I could achieve this using MediaBrowserServiceCompat
as it says in the official documentation here. But when I tried to use it in my project it says Unresolved reference: MediaBrowserServiceCompat
Although I've set Android Studio to import needed libraries automatically, I tried importing android.support.v4.*
, android.support.*
, androidx.*
explicitly, hoping it might work but it didn't as it turns out. So I went over to the GitHub repo of UAMP(Universal Android Music Player) for some help. I found the statement import androidx.media.MediaBrowserServiceCompat
in this file. But I couldn't find any library named so
And why my Manifest says MediaPlaybackService must extend android.app.service
?
How am I supposed to use it? Thanks!
Edit: I did a little bit of research and tinkering. I tried changing the service name in my Manifest and the associated class name as well to MyMediaBrowserServiceCompat
and magically it worked(sort of). So now, my question is, is it normal behavior? Should changing the service name really affect this situation? And if its so, how on Earth it works with different names(something not similar to the class name itself) on other peoples' machines? And secondly, now my code says There's a cycle in the inheritance hierarchy for this type
I searched the web and found this. So I know what that message means but I can't figure out how to solve it in this case. And my Manifest still says the same: MyMediaBrowserServiceCompat must extend android.app.service
My guess is that this is related to the dependency where MediaBrowserService is located. Without seeing the dependencies section in your build.gradle
it's difficult to know, but the MediaBrowserService is located in implementation 'androidx.media:media:1.1.0'
. Try adding that and you should be able to find it.
A note on the message about There's a cycle in the inheritance hierarchy for this type
: that's because you're essentially referring to the same class as both the parent and child and that won't work as it'll ask for the parent and just get itself back. The reason for it "working" is because you're now only referring to actual files that can be found since the class MyMediaBrowserService
exists. You'll need to update your service to actually inherit MediaBrowserServiceCompat
to get it working, and that should work when you have the dependency for it.