如何在 Android API >=19 中使用 mediaSession。

huangapple go评论76阅读模式
英文:

how to use mediaSession for android api >=19

问题

我正在尝试将 MediaSession 集成到我的 Service 中,但是使用 android.media.MediaSession 并不起作用,因为调用 mediaSession.release() 会给我一个错误,表示此调用仅在 API level 21 及以上可用,而我正在针对 API level 19

我已经搜索过了,似乎在 androidx.media 中也找不到它。对于使用 androidx 的用户,MediaSessionMediaSessionCompat 位于哪里呢?

英文:

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.TokenParcelable,并且是公共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.

huangapple
  • 本文由 发表于 2020年9月14日 12:21:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63878065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定