Posted by Nevin Mital – Developer Relations Engineer, Android Media
Today we are pleased to announce the full release of the Jetpack Media3 library. After sharing the first preview of the library at Android Developer Summit 2021, we’ve published several alpha and beta releases over the past several months to ensure a high-quality set of APIs that we now encourage everyone to adopt.
Media3 is the new home of APIs for creating rich audio and video experiences. If you use libraries like ExoPlayer, MediaCompat or Media2, you’ll find Media3 familiar. However, instead of using these separate libraries, Media3 provides a unified API for playback use cases, and extends to cover new use cases such as video editing and transcoding. The APIs are easy to use yet powerful, customizable to meet your needs, and reliable and optimized so you can build for a diverse Android device ecosystem.
In this blog post, we’ll focus on playback on Media3, so please stay tuned for an upcoming post where we’ll dive deeper into the video editing and transcoding APIs. As a brief introduction, the following table describes the key components for playback in Media3:
Our developer documentation has more details on these components. Let’s take a closer look at what this new library has to offer and how you can start using it.
Make it easy
A playback developer journey can introduce media3a by consolidating the APIs into a single library. Player An interface used by several classes Media session And Media control. This interface lists traditional high-level functions for audio and video playback, such as playback controls and the ability to query the properties of the currently playing media.
Having a common interface for all “player-like” components means it’s easy to create new instances of these objects:
val player = ExoPlayer.builder(context).build() |
Media3’s Media session And Media control It automatically reflects the status of connected entities. As a result, you can simplify your application architecture by removing links like ExoPlayer’s. MediaSessionConnector And easily follow the flow of logic through your application. Calling play()
on the Media control the action b Media sessionThen he passes it to the player.
Similarly, Media3 aims to handle background playback issues with ease. of PlayerNotificationManager ExoPlayer is no longer needed, as is Media3s MediaSession service And Media library service Automate media ad printing as needed. The library handles setting up, starting, and stopping the priority service for you as needed, but please also note some known issues covered in this comment.
ExoPlayer has been discontinued, long live ExoPlayer!
ExoPlayer has a new home and is the default implementation of the aforementioned player interface in Media3. A standalone ExoPlayer project, with a package name com.google.android.exoplayer2, will be discontinued soon, and future updates will be published in Media3. For the next few months, we will continue to publish equivalent releases of both Media3 and ExoPlayer to help you transition to Media3. For example, this means that ExoPlayer 2.18.5 and ExoPlayer in Media3 1.0.0 are identical except for their package names. However, this is only temporary and we will be removing the standalone ExoPlayer later this year, so we strongly recommend migrating to Media3 as soon as possible. The “Migrating to Media3” section below describes the process in more detail, including a script that does most of the work for you.
Note that Media3 is built with the same philosophy as ExoPlayer (and even by the same team!). In other words, Media3 maintains ExoPlayer’s customizable components, open source development on GitHub, pull requests and public issue tracking, to name a few similarities.
Migrating to Media3
As mentioned earlier, a standalone ExoPlayer project, with a package name com.google.android.exoplayer2, will be discontinued soon, so you’ll need to migrate to Media3 ExoPlayer to continue receiving updates. Other media APIs that should be migrated to Media3 include, but are not limited to; MediaSessionConnector, MediaBrowserServiceCompatAnd MediaBrowserCompat.
We’ve put together two key resources to help you make this migration as smooth as possible:
- A migration guide that guides you step by step through the process
- A migration script to convert standalone ExoPlayer project packages to compatible new modules and packages under Media3
The good news is that if you’re currently using ExoPlayer, no code changes are required and you don’t need to recompile or rewrite any customizations. Standalone ExoPlayer and Media3 ExoPlayer are identical except for the package name, and the conversion can be done automatically with the specified migration script. Before you begin, make sure you update your project to use the latest version of ExoPlayer. For full details and steps, please refer to the migration guide.
Also because Media3 is fully backwards compatible with previous media APIs MediaControllerCompat And MediaMetadataCompatYour existing integrations will continue to work as before after the migration. Note that new features such as controller customization are only available to customers using Media3. That is, for example, all old controllers, such as MediaControllerCompat, accepts the same set of commands available. You can identify the legacy controller by checking that. getControllerVersion() 0 is returned in MediaSession.ControllerInfo.
The power of Media3, in the palm of your hand
Media3 gives you many options to customize the feature to best suit your needs. The next few sections describe some such methods.
Play it your way.
Although ExoPlayer is the recommended player application for audio and video streaming applications, Media3 also promotes Simple bass player To reduce the number of methods you need to implement to integrate with a custom player. Start by applying Gateshead method. This is where you can declare. Order Supported by your player and configure metadata such as the index of the currently playing media item and the current timestamp.
class CustomPlayer : SimpleBasePlayer(looper) { |
of Simple bass player A class enforces the correct player state and handles notification of state changes to listeners. In addition, any methods from a Order You do not announce that they have been ignored, so that’s more GatesheadYou only need to apply the methods that are used correctly.
Better control over your orders
of Media session And Media control The APIs have also been updated to give you more control. With Media3, you can deploy your app’s playback capabilities on every monitor. Modify the commands available for the client application in On the relationship Your method MediaSession.callback. For example, to prevent a client application with a package name com.example.my client From getting access to “Find the next media item”. Player. Command:
var sessionCallback = object : MediaSession.Callback { |
Of course, like previous media APIs, you can add custom commands for your application. Create a new one to implement a custom command session order. Similar to above, controllers can grant access to this custom command by including it in the list of existing session commands. You can handle the custom order feature in On custom order Same method call back:
override fun onCustomCommand( |
You can also request that client applications display your custom order by including it in a Custom layout Call in on PostConnect of MediaSession.callback.
Next steps
We’d love for you to start using Media3 in your apps!
To start exploring the library, feel free to check out the demo application to see an example of audio and video playback, including how to integrate it with an archive session. Stay tuned to our developer guides for a more detailed guide on the various components in the upcoming Media3 landing. Our sample app, Universal Android Music Player, and our test tool, Media Control Test App, will also be updated to Media3 on their main branches in the coming weeks.
If you encounter any issues, have feature requests, or would like to share any other kind of feedback, please let us know using the Media3 issue tracker on GitHub. We look forward to hearing from you!