Ease the event of media apps for Put on OS with the media toolkit | by chiara chiappini | Android Builders | Dec, 2022

Over the previous two years, Put on OS utilization has grown with the discharge of latest units. Media apps to play music, hearken to podcasts, or observe guided exercises are actually very fashionable with customers.

On this weblog submit, you’ll learn to convey your media app to Put on OS smartwatches with the assistance of the newly launched Put on media toolkit and study extra about:

The Put on media toolkit is a set of libraries which accelerates the event of high-quality media apps for Put on OS. The toolkit is a part of the Horologist venture and gives a completely purposeful pattern app that you would be able to run to discover what you could possibly construct.

The toolkit makes use of the best-in-class libraries for media use circumstances, from an environment friendly and pleasant UI carried out with Compose for Put on OS, to Media3 to implement the playback. Your app might have particular necessities, resembling utilizing a proprietary media participant — on this case you possibly can undertake the UI implementation from the toolkit whereas nonetheless relying in your present participant.

While you design your media app, begin by contemplating two of crucial use circumstances:

Some customers would additionally like to make use of Put on OS media apps to begin and management media content material on the telephone: that is already doable by utilizing the newly launched Assistant expertise on the watch and Put on’s inbuilt media controls.

Chances are you’ll already concentrate on media particular challenges when growing an Android cell app. Watches have further concerns like:

So, growing for the watch means taking further issues into consideration to offer customers the very best expertise:

Let’s dive into every of those issues and see how the media toolkit can assist you to resolve these challenges.

Most Put on OS units have audio system. Whereas watch audio system can be utilized for calls and guided actions, they don’t ship the very best expertise for listening to media content material as they don’t seem to be designed for this goal.

To present the very best consumer expertise, your app ought to make certain to play audio when Bluetooth headphones or audio system are linked to the watch.

The Media Toolkit makes this simple to do. It gives a selected Media3 extension that decorates the ExoPlayer occasion and proactively stops unintended playback earlier than it emits sound. That is carried out by checking if the present audio output is a Bluetooth gadget. If not, the toolkit launches the Bluetooth settings move and permits the consumer to hook up with their headset.

Try the attemptToPlay perform to see how that is carried out.

You may see how easy and logical this reusable library code is when layered on prime of Media3 Participant.

Audio offload permits audio processing to be offloaded from the CPU to a devoted sign processor. This ends in higher performances and energy saving, which is especially necessary for apps on Put on OS.

The Media Toolkit gives help for audio offload through the AudioOffloadManager which configures and controls audio offload, enabling sleeping whereas your app is within the background and disabling whereas within the foreground.

Check out the pattern app to see how AudioOffloadManager is enabled.

Please observe that the next options are usually not at present supported by Audio offload:

If you’re unsure if audio offload is supported for a given audio format, use the AudioManager.isOffloadedPlaybackSupported() methodology.

For extra info, see the Exoplayer docs.

The Media Toolkit gives some benchmark assessments that you would be able to run to generate perfetto traces. To match CPU efficiency when audio offload is enabled or disabled, run PlaybackBenchmark. This streams for 30 seconds. First it fetches for 10 seconds and after buffering, performs 25 seconds of audio.

See the next snapshots taken from ui.perfetto.dev for playback with audio offload disabled and enabled. These screenshots have been taken working PlaybackBenchmark on Pixel Watch linked to Pixel Buds.

Audio offload disabled
Audio offload enabled

Evaluating the two photographs it’s simple to see that:

You may take a deeper have a look at what processes are working by working PlaybackBenchmark on Android Studio and importing the outcomes on ui.perfetto.dev.

If you wish to study extra about Macrobenchmark, learn extra on macrobenchmark overview.

While you develop for Put on, you must count on customers to have restricted community connectivity. Many customers go away their telephone behind once they play media. And, listening to downloaded content material brings important battery financial savings for the consumer even when they do have an obtainable community connection.

The toolkit makes it easy to optimize media downloads. It gives a MediaDownloadService carried out utilizing Media3’s DownloadManager and Androidx Work Supervisor to schedule downloads. Media3 begins all the proper notifications and foreground companies, and the pattern app code configures the Work Supervisor to run the downloads when Wi-Fi connection is out there to make sure higher efficiency. That is achieved by utilizing the NetworkAwareness module which permits builders to map community operations with community kind.

To summarize, by utilizing the MediaDownloadService you possibly can make sure that customers have dependable, performant downloads to allow them to play media on the go.

The Put on media toolkit gives a UI module to assist construct UI screens on your app.

The UI module makes use of Compose for Put on OS which brings many parts tailor-made to the watch and ensures your app adheres to Materials design. It additionally gives a pleasant developer expertise with Android Studio integration resembling previews and animation instruments. Compose for Put on OS and the toolkit include built-in accessibility and translations throughout all screens.

You may simply use and adapt the Put on media toolkit screens to the precise fashion of your app. The screens observe core design ideas, showcased by the media pattern app:

Participant and Library screens
Entity web page
Quantity display

By working the pattern app, you possibly can instantly see how the toolkit helps you construct the app screens whereas following the ideas listed above.

An Ongoing Exercise is a brand new function in Put on OS 3 that permits an Ongoing Notification to look on further surfaces throughout the Put on OS consumer interface.

This permits customers to remain extra engaged with lengthy working actions. Health and media apps profit from this function. An Ongoing Exercise reveals up on the watchface and on recents apps.

Ongoing Exercise

Design your app to open the participant display when the Ongoing Exercise notification is tapped. This permits the consumer to shortly carry out an motion, resembling pausing a tune whereas it’s enjoying.

Put on OS mechanically takes care of making Ongoing Actions for media apps if you happen to use Media 3; you simply want to supply an intent for opening the app. Because of this the pattern app merely gives a deep hyperlink to the Participant Display to get the Ongoing Exercise to open the Participant display.

An enormous a part of making certain your app has good efficiency comes right down to optimizing playback for streaming and downloaded music, and the obtain operation.

The Put on media toolkit helps to construct the muse of a performant app, resembling offering the Community Consciousness module to decide on the higher connection for a selected operation, however there are particular app decisions that you have to contemplate to make an app carry out properly on the watch.

Concerns for streaming:

Concerns for downloading content material:

Concerns for playback (streamed and downloaded music):

Construct your media app on Put on OS by utilizing the Put on media toolkit. The toolkit has been designed to make growth simpler whereas making certain media particular behaviors are carried out and Put on media design ideas are adopted.

Checkout our Android Developer Summit 2022 speak, Constructing media apps on Put on OS, for an ideal overview on this subject.

d.android.com/put on is the very best place to test the most recent steering associated to Put on OS growth. And don’t neglect to supply suggestions to the Horologist venture which hosts the Put on media toolkit.

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles