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:
- How the toolkit helps implement media use circumstances on Put on OS.
- Media particular behaviors and distinctive UI challenges on the watch.
- New Put on OS 3 options that may profit a media app.
- How one can tailor your content material for higher efficiency on Put on OS.
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:
- Play downloaded content material: obtain music or podcasts, so customers can pay attention when they’re understanding with no need a community connection
- Streaming: hearken to music, podcasts, or a radio station, utilizing any obtainable community
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:
- Inbuilt audio system are usually not designed for music playback
- Smaller batteries and subsequently restricted energy
- Restricted, or various, community connectivity
- Battery sensitivity to poor LTE sign
So, growing for the watch means taking further issues into consideration to offer customers the very best expertise:
- Keep away from enjoying media on watch audio system and use Bluetooth audio system/headsets
- Allow audio offload
- Keep away from pinging the community connection except completely essential
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.
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.
Evaluating the two photographs it’s simple to see that:
- The CPU is just not continuously working when audio offload is enabled.
- The CPU frequency goes down (round 449 MHz) for longer intervals when audio offload is enabled whereas when audio offload is disabled the CPU frequency oscillates extra steadily in the direction of greater values.
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:
- Apps needs to be organized utilizing 2 swipeable screens: Participant and Library
- The Participant display provides fast entry to necessary playback actions. The Participant display ought to have a 5 button format. This ensures our minimal faucet targets are met and customers can management the media simply while on the go.
- The Library display permits customers to seek out media to play. Maintain the content material hierarchy as flat as doable within the Library display to scale back complexity.
- Upon tapping on content material from the Library, customers needs to be offered with entity pages, such a Playlist. An entity web page provides customers extra details about what a media merchandise incorporates. It additionally incorporates necessary consumer actions like handbook obtain and play / shuffle.
- Adapt actions relying on the kind of content material: when you’ve got a podcast chances are you’ll need to enable the consumer to quick ahead 30 seconds as a substitute of skipping to subsequent.
- You may customise the icons and font in your media app, however the minimal font measurement is 12dp. For main content material, resembling tune title and artist title, the font measurement needs to be a minimum of 14dp.
- For units with an RSB (rotating facet button) or bezel, improve the consumer expertise by utilizing this interplay to alter the amount or scroll by content material.
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.
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:
- Optimize the content material by selecting a low bitrate for streaming, resembling 48kbps and codecs resembling AAC and MP3.
- Optimize the prefetch technique for photographs and tracks to make sure persevering with playback whenever you lose connection quickly. Keep away from the expertise of a consumer coming into an space with weak and no sign, listening to streamed content material, and music abruptly stopping as a result of community connection is misplaced.
- Take a look at your app in all community configurations: Wi-Fi, LTE, watch linked to telephone through Bluetooth. Additionally take a look at what occurs when the watch switches between networks.
Concerns for downloading content material:
- Utilizing WiFi is significantly better than utilizing a Bluetooth connection to obtain media onto a watch. If the consumer is on a LTE plan, it’s a good suggestion to test if the consumer is conscious that the obtain operation might be utilizing LTE knowledge, which may doubtlessly change into an costly operation.
Concerns for playback (streamed and downloaded music):
- Customers listening to media content material on a watch shouldn’t be experiencing extreme battery drain: even when a community is out there, restrict the visitors by sending much less frequent pings to the server and select a decrease art work picture decision.
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.