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?
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 theandroidx.media
artifact).The class remains in the old package simply because the nested class,
MediaSessionCompat.Token
isParcelable
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.