英文:
how to use mediaSession for android api >=19
问题
我正在尝试将 MediaSession
集成到我的 Service
中,但是使用 android.media.MediaSession
并不起作用,因为调用 mediaSession.release()
会给我一个错误,表示此调用仅在 API level 21
及以上可用,而我正在针对 API level 19
。
我已经搜索过了,似乎在 androidx.media 中也找不到它。对于使用 androidx 的用户,MediaSession
或 MediaSessionCompat
位于哪里呢?
英文:
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
得分: 2
根据使用媒体会话指南,正确的类仍然是android.support.v4.media.session.MediaSessionCompat
(您会注意到该类仍然位于'AndroidX'文档集合下,并且仍然是androidx.media
构件的一部分)。
该类仍然保留在旧的包中,只是因为嵌套类MediaSessionCompat.Token
是Parcelable
,并且是公共API的一部分,因此在与仍针对旧的Support Library类构建的应用保持兼容时,不能更改其包名称。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论