how to use mediaSession for android api >=19

453 views Asked by At

I'm trying to incorporate MediaSession into my Service, but, using the android.media.MediaSession doesn't work because calling mediaSession.release() gives me an error saying call is available only in api level 21 while I'm targeting api level 19.

I had searched, and it seems it's not available in androidx.media as well. Where is the MediaSession or MediaSessionCompat located for androidx users?

1

There are 1 answers

9
ianhanniballake On BEST ANSWER

As per the Using a media session guide, the correct class is still android.support.v4.media.session.MediaSessionCompat (you'll note that the class still remains under the 'AndroidX' set of documentation and is still part of the androidx.media artifact).

The class remains in the old package simply because the nested class, MediaSessionCompat.Token is Parcelable and is part of the public API and therefore cannot have its package named while remaining compatible with apps still built against the old Support Library classes.