I wrote a class which will handle the MediaPlaybackService in android. But the code is not working.
My code for binding the serviceconnection is as follows:
Two problems here:
1 - The IMediaPlaybackService
is not accessible from other applications. This is because this service is not exported in the manifest file of the Music app since Gingerbread (Android 2.3) (see packages/apps/Music/AndroidManifest.xml
in the Android source code):
When the value is false
, only components of the same application or applications with the same user ID can start the service or bind to it.
The Music app could be rebuilt changing the XML attribute to true
and installed again on the device, but this would lead to the problem number 2
2 - The MediaPlaybackService
is part of the built-in Android Music app and it is used only by this application internally. If a 3rd party music player is installed on the device, this won’t use the MediaPlaybackService
and no information about the playback will be available through its API.
Unfortunately, no public system service provides the same API to get access to information about the current audio track or to interact with the current playback.
This is probably because the Android team decided to let each music player manage the internal information about the audio track, rather than relying on a central service that keeps track of what’s being played.