Background Audio in Android With MediaSessionCompat

One of the most popular uses for mobile devices is playing back audio through music streaming services, downloaded podcasts, or any other number of audio sources. While this is a fairly common feature, it's hard to implement, with lots of different pieces that need to be built correctly in order to give your user the full Android experience. 移动设备最流行播放音频,下载播客或任何其他音频源是通过音乐流服务。虽然这是一个相当常见的功能,它很难实现,有很多不同的部分需要正确构建,以给您的用户完整的Android体验。

In this tutorial you will learn about MediaSessionCompat from the Android support library, and how it can be used to create a proper background audio service for your users.在本教程中,您将从Android支持库中了解MediaSessionCompat,以及如何使用它为用户创建合适的背景音频服务。

Setup

The first thing you will need to do is include the Android support library into your project. This can be done by adding the following line into your module's build.gradle file under the dependencies node.您需要做的第一件事是将Android支持库包含到您的项目中。这可以通过在模块的build.gradle文件中的dependencies节点下添加以下行来完成。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐