Media3 is ready to play!

Posted by Nevin Mital - Developer Relations Engineer, Android Media

Today, we’re pleased to announce the full release of the Jetpack Media3 library. After sharing a first look at the library at Android Developer Summit 2021, we 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 for APIs that enable you to create rich audio and video experiences. If you’ve used libraries like ExoPlayer, MediaCompat, or Media2, you’ll find Media3 to be familiar. However, instead of using these separate libraries, Media3 provides a unified API for playback use-cases and also expands to cover new use-cases like video editing and transcoding. The APIs are simple to use yet powerful, customizable to meet your needs, and reliable and optimized so you can build for the diverse Android device ecosystem.

In this blog post, we’ll focus on the playback APIs in 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 key components for playback in Media3:

Player

An interface that defines traditional high-level functionality for an audio or video player, such as playback controls.

ExoPlayer

The default implementation of the Player interface in Media3.

MediaSession

An API that advertises media playback to and receives playback command requests from external clients.

MediaSessionService

A service that holds a MediaSession to enable background playback.

MediaLibraryService

A service that additionally allows you to expose a content library to external clients.

MediaController

An API that is generally used by external clients to retrieve playback information and send playback command requests to your media app. Complementary to a MediaSession. Examples of external clients include the notification and lock screen media controls on mobile and large screen devices, Android Auto, WearOS, and Google Assistant.

MediaBrowser

An API that additionally enables external clients to navigate your media app’s content library. Complementary to a MediaLibraryService.

Our developer documentation has more details on these components. Let’s take a closer look into what this new library offers and how you can start using it.

Keeping it simple

By consolidating the APIs for the playback developer journey into a single library, Media3 is able to introduce a Player interface that is used by several components, such as MediaSession and MediaController. This interface outlines traditional high-level functionality for audio and video playback, such as playback controls and the ability to query properties of the currently playing media.

Having a common interface for all “player-like” components means that creating new instances of these objects is straightforward:

val player = ExoPlayer.builder(context).build() val session = MediaSession.Builder(context, player).build() val controller = MediaController.Builder(context, session.token).build()

Media3's MediaSession and MediaController will automatically reflect the state of the components they're connected to. As a result, you can also simplify your app’s architecture by removing connectors like ExoPlayer’s MediaSessionConnector and more easily follow the flow of logic through your app. Calling play() on the MediaController will forward the action to the MediaSession, which will then forward it to the player.

Similarly, Media3 aims to make background playback cases easier to handle. The PlayerNotificationManager from ExoPlayer is no longer needed, as Media3’s MediaSessionService and MediaLibraryService automatically handle publishing a media notification as needed. The library handles configuring, starting, and stopping a foreground service for you as needed, but please also note some known issues summarized in this comment.

ExoPlayer is deprecated, long live ExoPlayer!

ExoPlayer has a new home and is the default implementation of the aforementioned Player interface in Media3. The standalone ExoPlayer project, with package name com.google.android.exoplayer2, will soon be discontinued, and future updates will be published in Media3. For the next few months, we’ll continue publishing equivalent releases of both Media3 and ExoPlayer to help you make the transition to Media3. For example, this means that ExoPlayer 2.18.5 and ExoPlayer in Media3 1.0.0 are identical aside from their package names. However, this is only temporary and we will deprecate the standalone ExoPlayer later this year, so we highly recommend migrating to Media3 as soon as possible. The “Migrating to Media3” section below describes the process in more detail, which includes a script that handles most of the work for you.

Note that Media3 is developed with the same philosophy as ExoPlayer (and in fact, is developed by the same team!). In other words, Media3 retains ExoPlayer’s customizable components, open source development on GitHub, receptivity to pull requests, and public issue tracker, to name a few similarities.

Migrating to Media3

As mentioned previously, the standalone ExoPlayer project, with package name com.google.android.exoplayer2, will soon be discontinued, so to continue receiving updates, you will need to migrate to Media3 ExoPlayer. Other Media APIs that should be migrated to Media3 include, but are not limited to, MediaSessionConnectorMediaBrowserServiceCompat, and MediaBrowserCompat.

We’ve prepared two key resources to help you achieve this migration as smoothly as possible:

  1. migration guide to walk you through the process step-by-step
  2. migration script to convert your standalone ExoPlayer project packages to the corresponding new modules and packages under Media3

The good news is that if you’re currently using ExoPlayer, there’s no need for any code changes and no need to re-integrate or re-write any customizations. The standalone ExoPlayer and Media3 ExoPlayer are identical aside from the package name, and the conversion can be done automatically with the aforementioned migration script. Just make sure you’ve updated your project to use the latest version of ExoPlayer before getting started. For full details and steps, please refer to the migration guide.

Furthermore, since Media3 is fully backwards-compatible with prior media APIs such as MediaControllerCompat and MediaMetadataCompat, your existing integrations will continue to work as before even after the migration. Note that new features such as per-controller customization of commands are only available for clients using Media3. That is to say, for example, all legacy controllers, such as MediaControllerCompat, will receive the same set of available commands. You can identify a legacy controller by checking if getControllerVersion() returns 0 in the MediaSession.ControllerInfo.

The power of Media3, in the palm of your hand

Media3 offers several options for you to adjust its behavior to better fit your needs. The next few sections describe some such mechanisms.

Play it your own way

Although ExoPlayer is the recommended Player implementation to use for audio and video streaming apps, Media3 also introduces the SimpleBasePlayer to minimize the number of methods you need to implement to integrate with a custom player. Start by implementing the getState method. This is where you can declare the Command set supported by your player and configure metadata such as the currently playing media item index and the current timestamp.

class CustomPlayer : SimpleBasePlayer(looper) { override fun getState(): State { // Set available Commands // Configure playWhenReady, mediaItemIndex, currentPosition, etc. } // Implement methods required by available Commands }

The SimpleBasePlayer class will enforce valid player state and handle informing listeners of state changes. Additionally, any methods related to a Command you don’t declare as available are ignored, so beyond getState, you only need to implement the methods that will actually be used.

Better control over your commands

The MediaSession and MediaController APIs have also been updated to give you more control. With Media3, you can advertise your app’s playback capabilities on a per-controller basis. Modify the commands available to a client app in the onConnect method of your MediaSession.Callback. For example, to prevent a client app with package name com.example.myClient from having access to the “seek to next media item” Player.Command:

var sessionCallback = object : MediaSession.Callback { override fun onConnect( session: MediaSession, controller: MediaSession.ControllerInfo ): MediaSession.ConnectionResult { val connectionResult = super.onConnect(session, controller) if (controller.packageName == "com.example.myClient") { val availablePlayerCommands = connectionResult.availablePlayerCommands.buildUpon() .remove(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM) // Disallow myClient from being able to skip to the next media item .build() return MediaSession.ConnectionResult.accept( connectionResult.availableSessionCommands, availablePlayerCommands ) } return connectionResult // Other clients retain normal command access } } var mediaSession = MediaSession.Builder(context, player) .setCallback(sessionCallback) // Remember to set the callback on your MediaSession! .build()

Creating custom commands

Of course, as with the previous media APIs, you can add custom commands tailored to your app. To implement a custom command, create a new SessionCommand. Similar to as shown above, you can give controllers access to this custom command by including it in the list of available session commands. You can handle custom command behavior in the onCustomCommand method of the same Callback:

override fun onCustomCommand( session: MediaSession, controller: MediaSession.ControllerInfo, customCommand: SessionCommand, args: Bundle ): ListenableFuture<SessionResult> { if (customCommand.customAction == MY_CUSTOM_COMMAND) { // Do custom action return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS)) } // Return error for invalid custom command return Futures.immediateFuture(SessionResult(SessionResult.RESULT_ERROR_BAD_VALUE)) }

You can also ask client apps to display your custom command by including it in a setCustomLayout call in the onPostConnect method of the MediaSession.Callback.

Next steps

We’d love for you to start using Media3 in your app! 

To start exploring the library, feel free to check out the demo app to see an example of audio and video playback, including how to integrate with a media session. Stay tuned to our developer guides for more detailed guidance on the different components in Media3 landing soon. Our sample app, the Universal Android Music Player, and our testing tool, the Media Controller Test app, will also be updated to Media3 on their main branches in the coming weeks.

If you run into any issues, have any feature requests, or would like to share any other sort of feedback, please let us know using the Media3 issue tracker on GitHub. We look forward to hearing from you!

Beta Channel Update for Desktop

 The Beta channel has been updated to 112.0.5615.39 for Windows,Linux and Mac

A full list of changes in this build is available in the log. Interested in switching release channels? Find out how here. If you find a new issues, please let us know by filing a bug. The community help forum is also a great place to reach out for help or learn about common issues.


Srinivas Sista

Chrome Beta for Android Update

Hi everyone! We've just released Chrome Beta 112 (112.0.5615.37) for Android. It's now available on Google Play.

You can see a partial list of the changes in the Git log. For details on new features, check out the Chromium blog, and for details on web platform updates, check here.

If you find a new issue, please let us know by filing a bug.

Krishna Govind
Google Chrome

Launching new #WeArePlay stories from India

Posted by Parul Tyagi, Developer Marketing

Every month, over 2.5 billion people visit Google Play to discover millions of apps and games, which are created by people with all sorts of backgrounds, who founded companies big and small.

#WeArePlay celebrates this community of people building apps and games businesses, with monthly spotlights of founders from across the world.

Last summer we went on a virtual tour of the USA, sharing stories from every state, and today we’re continuing our tour across the world with our next stop: India.

To kick us off, we are spotlighting 20 stories from across the country, with many more coming throughout the year.

Moving text reads #WeArePlay INDIA Discover now g.co/play/weareplay-india Google Play

First, we begin with Pramit from Gurugram, Haryana. He was climbing the corporate ladder when medication he was taking damaged his retina, therefore losing his vision. No longer able to read, he required help from friends and family to perform daily tasks. One day, when a friend was booking a driver for him, Pramit got the idea to create a tool that could function exactly like a virtual friend through voice-activated commands. Using his app Louie Voice Control, people can operate other apps using their voice, making technology infinitely more accessible for the visually impaired.

#WeArePlay Pramit Visioapps Technology Gurugram, Haryana g.co/play/weareplay-india Google Play

Next, meet Sourav and Gunjan from Kolkata, West Bengal. When Sourav and Gunjan had their son, they noticed how fascinated he was watching videos on their phones. This gave Gunjan the idea to provide meaningful screen time for him by making educational games for young children. Fast forward to today and they have 42 apps, including Yoga for Kids where youngsters follow along with simple yoga poses and unlock animated pets as rewards.

#WeArePlay Sourav & Gunjan Gunjanapps Studios Kolkata, West Bengal g.co/play/weareplay-india Google Play

Now onto Tejas from Rajkot, Gurajat. He was always determined to go his own way in life and pursue programming, rather than his family's construction business. After discovering how popular cooking games are, his company TheAppGuruz makes versions catered specifically for Asian audiences - with some full of Indian dishes and specialties. Now, Tejas and his team are developing more cooking simulation titles, as well as traditional board games for a global audience.

#WeArePlay Tejas TheAppGuruz Rajkot, Gujarat g.co/play/weareplay-india Google Play

And last but not least, Anshul and Rohan from Mumbai, Maharashtra. After bonding over their experiences in overcoming mental health struggles, they discovered they had the same goal: to create something in the mental wellness space. So they built Evolve - an app with guided meditations, breathing exercises and daily affirmations. During the pandemic, the pair realized the LGBTQ+ community was one of the most underserved in mental health support, so they adapted Evolve to meet their needs.

#WeArePlay Rohan &Anshul Evolve Mumbai, Maharashtra g.co/play/weareplay-india Google Play

Check out all the stories now at g.co/play/weareplay-india and stay tuned for even more coming soon.


How useful did you find this blog post?

Launching new #WeArePlay stories from India

Posted by Parul Tyagi, Developer Marketing

Every month, over 2.5 billion people visit Google Play to discover millions of apps and games, which are created by people with all sorts of backgrounds, who founded companies big and small.

#WeArePlay celebrates this community of people building apps and games businesses, with monthly spotlights of founders from across the world.

Last summer we went on a virtual tour of the USA, sharing stories from every state, and today we’re continuing our tour across the world with our next stop: India.

To kick us off, we are spotlighting 20 stories from across the country, with many more coming throughout the year.

Moving text reads #WeArePlay INDIA Discover now g.co/play/weareplay-india Google Play

First, we begin with Pramit from Gurugram, Haryana. He was climbing the corporate ladder when medication he was taking damaged his retina, therefore losing his vision. No longer able to read, he required help from friends and family to perform daily tasks. One day, when a friend was booking a driver for him, Pramit got the idea to create a tool that could function exactly like a virtual friend through voice-activated commands. Using his app Louie Voice Control, people can operate other apps using their voice, making technology infinitely more accessible for the visually impaired.

#WeArePlay Pramit Visioapps Technology Gurugram, Haryana g.co/play/weareplay-india Google Play

Next, meet Sourav and Gunjan from Kolkata, West Bengal. When Sourav and Gunjan had their son, they noticed how fascinated he was watching videos on their phones. This gave Gunjan the idea to provide meaningful screen time for him by making educational games for young children. Fast forward to today and they have 42 apps, including Yoga for Kids where youngsters follow along with simple yoga poses and unlock animated pets as rewards.

#WeArePlay Sourav & Gunjan Gunjanapps Studios Kolkata, West Bengal g.co/play/weareplay-india Google Play

Now onto Tejas from Rajkot, Gurajat. He was always determined to go his own way in life and pursue programming, rather than his family's construction business. After discovering how popular cooking games are, his company TheAppGuruz makes versions catered specifically for Asian audiences - with some full of Indian dishes and specialties. Now, Tejas and his team are developing more cooking simulation titles, as well as traditional board games for a global audience.

#WeArePlay Tejas TheAppGuruz Rajkot, Gujarat g.co/play/weareplay-india Google Play

And last but not least, Anshul and Rohan from Mumbai, Maharashtra. After bonding over their experiences in overcoming mental health struggles, they discovered they had the same goal: to create something in the mental wellness space. So they built Evolve - an app with guided meditations, breathing exercises and daily affirmations. During the pandemic, the pair realized the LGBTQ+ community was one of the most underserved in mental health support, so they adapted Evolve to meet their needs.

#WeArePlay Rohan &Anshul Evolve Mumbai, Maharashtra g.co/play/weareplay-india Google Play

Check out all the stories now at g.co/play/weareplay-india and stay tuned for even more coming soon.


How useful did you find this blog post?

What’s new in the Jetpack Compose March ’23 release

Posted by Jolanda Verhoef, Android Developer Relations Engineer

Today, as part of the Compose March ‘23 Bill of Materials, we’re releasing version 1.4 of Jetpack Compose, Android's modern, native UI toolkit that is used by apps such as Booking.com, Pinterest, and Airbnb. This release contains new features like Pager and Flow Layouts, and new ways to style your text, such as hyphenation and line-break behavior. It also improves the performance of modifiers and fixes a number of bugs.

Swipe through content with the new Pager composable

Compose now includes out-of-the-box support for vertical and horizontal paging between different content. Using VerticalPager or HorizontalPager enables similar functionality to the ViewPager in the view system. However, just like the benefits of using LazyRow and LazyColumn, you no longer need to create an adapter or fragments! You can simply embed a composable inside the Pager:

// Display 10 items HorizontalPager(pageCount = 10) { page -> // Your specific page content, as a composable: Text( text = "Page: $page", modifier = Modifier.fillMaxWidth() ) }

ALT TEXT

These composables replace the implementation in the Accompanist library. If you already use the Accompanist implementation, check out the migration guide. See the Pager documentation for more information.

Get your content flowing with the new Flow Layouts

FlowRow and FlowColumn provide an efficient and compact way to lay out items in a container when the size of the items or the container are unknown or dynamic. These containers allow the items to flow to the next row in the FlowRow or next column in the FlowColumn when they run out of space. These flow layouts also allow for dynamic sizing using weights to distribute the items across the container.

Here’s an example that implements a list of filters for a real estate app:

ALT TEXT

@Composable fun Filters() { val filters = listOf( "Washer/Dryer", "Ramp access", "Garden", "Cats OK", "Dogs OK", "Smoke-free" ) FlowRow( horizontalArrangement = Arrangement.spacedBy(8.dp) ) { filters.forEach { title -> var selected by remember { mutableStateOf(false) } val leadingIcon: @Composable () -> Unit = { Icon(Icons.Default.Check, null) } FilterChip( selected, onClick = { selected = !selected }, label = { Text(title) }, leadingIcon = if (selected) leadingIcon else null ) } } }

Performance improvements in Modifiers

The major internal Modifier refactor we started in the October release has continued, with the migration of multiple foundational modifiers to the new Modifier.Node architecture. This includes graphicsLayer, lower level focus modifiers, padding, offset, and more. This refactoring should bring performance improvements to these APIs, and you don't have to change your code to receive these benefits. Work on this continues, and we expect even more gains in future releases as we migrate Modifiers outside of the ui module. Learn more about the rationale behind the changes in the ADS talk Compose Modifiers deep dive.

Increased flexibility of Text and TextField

Along with various performance improvements, API stabilizations, and bug fixes, the compose-text 1.4 release brings support for the latest emoji version, including backwards compatibility with older Android versions 🎉🙌. Supporting this requires no changes to your application. If you’re using a custom emoji solution, make sure to check out PlatformTextStyle(emojiSupportMatch).

In addition, we’ve addressed one of the main pain points of using TextField. In some scenarios, a text field inside a scrollable Column or LazyColumn would be obscured by the on-screen keyboard after being focused. We re-worked core parts of scroll and focus logic, and added key APIs like PinnableContainer to fix this bug.

Finally, we added a lot of new customization options to Text and its TextStyle:

  • Draw outlined text using TextStyle.drawStyle.
  • Improve text transition and legibility during animations using TextStyle.textMotion.
  • Configure line breaking behavior using TextStyle.lineBreak. Use built-in semantic configurations like Heading, Paragraph, or Simple, or construct your own LineBreak configuration with the desired Strategy, Strictness, and WordBreak values.
  • Add hyphenation support using TextStyle.hyphens.
  • Define a minimum number of visible lines using the minLines parameter of the Text and TextField composables.
  • Make your text move by applying the basicMarquee modifier. As a bonus, because this is a Modifier, you can apply it to any arbitrary composable to make it move in a similar marquee-like fashion!
  • ALT TEXT
    Marquee text using outline with shapes stamped on it using the drawStyle API.

Improvements and fixes for core features

In response to developer feedback, we have shipped some particularly in-demand features & bug fixes in our core libraries:
  • Test waitUntil now accepts a matcher! You can use this API to easily synchronize your test with your UI, with specific conditions that you define.
  • animatedContent now correctly supports getting interrupted and returning to its previous state.
  • Accessibility services focus order has been improved: the sequence is now more logical in common situations, such as with top/bottom bars.
  • AndroidView is now reusable in LazyList if you provide an optional onReset lambda. This improvement lets you use complex non-Compose-based Views inside LazyLists.
  • Color.lerp performance has been improved and now does zero allocations: since this method is called at high frequency during fade animations, this should reduce the amount of garbage collection pauses, especially on older Android versions.
  • Many other minor APIs and bug fixes as part of a general cleanup. For more information, see the release notes.

Get started!

We’re grateful for all of the bug reports and feature requests submitted to our issue tracker - they help us to improve Compose and build the APIs you need. Continue providing your feedback, and help us make Compose better!

Wondering what’s next? Check out our updated roadmap to see the features we’re currently thinking about and working on. We can’t wait to see what you build next!

Happy composing!