Can MediaPlaybackservice be used for getting information of currently playing audio file in android?

前端 未结 1 445
栀梦
栀梦 2021-01-26 05:34

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:



        
相关标签:
1条回答
  • 2021-01-26 05:46

    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):

    <service android:name="com.android.music.MediaPlaybackService" 
        android:exported="false" />
    

    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.

    0 讨论(0)
提交回复
热议问题