Android Builders Weblog: Media3 1.8.0

0
1
Android Builders Weblog: Media3 1.8.0



Android Builders Weblog: Media3 1.8.0

Posted by Toni Heidenreich – Engineering Supervisor

This launch contains a number of bug fixes, efficiency enhancements, and new options. Learn on to search out out extra, and as at all times please take a look at the complete launch notes for a complete overview of modifications on this launch.

Scrubbing in ExoPlayer

This launch introduces a scrubbing mode in ExoPlayer, designed to optimize efficiency for frequent, user-driven seeks, like dragging a search bar deal with. You may allow it with ExoPlayer.setScrubbingModeEnabled(true). We have additionally built-in this into PlayerControlView within the UI module the place it may be enabled with both time_bar_scrubbing_enabled=”true” in XML or the setTimeBarScrubbingEnabled(boolean) technique. Media3 1.8.0 incorporates the primary batch of scrubbing enhancements, with extra to come back in 1.9.0!

moving image showing repeated seeking while scrubbing with scrubbing mode off in ExoPlayer

Repeated in search of whereas scrubbing with scrubbing mode OFF

moving image showing repeated seeking while scrubbing with scrubbing mode on in ExoPlayer

Repeated in search of whereas scrubbing with scrubbing mode ON

Reside streaming adverts with HLS interstitials

Extending the preliminary help for VOD in Media3 1.6.0, HlsInterstitialsAdsLoader now helps stay streams and asset lists for all of your server-guided advert insertion (SGAI) wants. The Google Advertisements Supervisor group explains how SGAI works. Observe our documentation for tips on how to combine HLS interstitals into your app.

chart of HLS intertitials processing flow from content server to ads server to Exoplayer

HLS interstitials processing circulate

Length retrieval with out playback

MetadataRetriever has been considerably up to date – it is now utilizing an AutoCloseable sample and allows you to retrieve the period of media objects with out playback. This implies Media3 now affords the complete performance of the Android platform MediaMetadataRetriever however with out having to fret about machine particular quirks and cross-process communication (some elements like body extraction are nonetheless experimental, however we’ll combine them correctly sooner or later).

attempt {
  MetadataRetriever.Builder(context, mediaItem).construct().use {
     val trackInfo = it.retrieveTrackGroups().await()
     val period = it.retrieveDurationUs().await()
  }
} catch (e: IOException) {
  handleFailure(e)
}

Partial downloads, XR audio routing and extra environment friendly playback

There have been a number of different enhancements and bug fixes throughout ExoPlayer and playback associated parts. To call just some:

    • Downloader implementations now help partial downloads, with a brand new PreCacheHelper to arrange handbook caching of single objects. This can be built-in into ExoPlayer’s DefaultPreloadManager in Media3 1.9.0 for an much more seamless caching and preloading expertise.
    • When created with a Context with a digital machine ID, ExoPlayer now routinely routes the audio to the digital XR machine for that ID.
    • We enabled extra environment friendly interactions with Android’s MediaCodec, for instance skipping buffers that aren’t wanted earlier within the pipeline.

Playback resumption in demo app and higher notification defaults

The MediaSession module has just a few modifications and enhancements for notification dealing with. It is now protecting notifications for longer by default, for instance when playback is paused, stopped or failed, so {that a} person has extra time to renew playback in your app. Notifications for stay streams (particularly with DVR home windows) additionally turned extra helpful by eradicating the complicated DVR window period and progress from the notification.

The media session demo app now additionally helps playback resumption to showcase how the function may be built-in into your app! It permits the person to renew playback lengthy after your app has been terminated and even after reboot.

Media resumption notification after device reboot

Media resumption notification after machine reboot

Sooner trim operations with edit record help

We’re persevering with so as to add optimizations for sooner trim operations to Transformer APIs. Within the new 1.8.0 launch, we launched help for trimming utilizing MP4 edit lists. Name experimentalSetMp4EditListTrimEnabled(true) to make trim-only edits considerably sooner.

val transformer = Transformer.Builder(requireContext())
        .addListener(transformerListener)
        .experimentalSetMp4EditListTrimEnabled(true)
        .construct()

A typical trimming operation typically requires a full re-transcoding of the video, even for a easy trim. This meant decoding, re-encoding the complete file, which is a time-consuming and resource-intensive course of. With MP4 edit record help, Transformer can now carry out “trim-only” edits far more effectively. As a substitute of re-encoding, it leverages the prevailing encoded samples and defines a “pre-roll” throughout the edit record. This pre-roll basically tells the participant the place to start out playback inside an present encoded pattern, successfully skipping the undesirable starting portion.

The next diagram illustrates how this works:

processing overview for faster trim optimizations

Processing overview for sooner trim optimizations

As illustrated above, every file incorporates encoded samples and every pattern begins with a keyframe. The pink line signifies the meant clip level within the unique file, permitting us to soundly discard two first samples. The main distinction on this method lies in how we deal with the third encoded pattern. As a substitute of operating a transcoding operation, we transmux this pattern and outline a pre-roll for a video begin place. This considerably accelerates the export operation; nonetheless this optimization is simply relevant if no different results are utilized. Participant implementations can also ignore the pre-roll part of the ultimate video and play from the beginning of the encoded pattern.

Chipset particular optimizations with CodecDbLite

CodecDBLite optimizes two parts of encoder configuration on a chipset-by-chipset foundation: codec choice and B-frames. Relying on the chipset, these parameters can have both a constructive or opposed impression on video high quality. CodecDB Lite leverages benchmark information collected on manufacturing gadgets to suggest a configuration that achieves the utmost user-perceived high quality for the developer’s goal bitrate. By enabling CodecDB Lite, builders can leverage superior video codecs and options with out worrying about whether or not or not they work on a given machine.

To make use of CodecDbLite, merely name setEnableCodecDbLite(true) when constructing the encoder manufacturing unit:

val transformer =
    Transformer.Builder()
        .setEncoderFactory(
            DefaultEncoderFactory.Builder()
                .setEnableCodecDbLite(true)
                .construct()
        )
        .construct()

New Composition demo

The Composition Demo app has been refreshed, and is now constructed totally with Kotlin and Compose to showcase superior multi-asset modifying capabilities in Media3. Our group is actively extending the APIs, and future releases will introduce extra superior modifying options, comparable to transitions between media objects and different extra superior video compositing settings.

Adaptive-first: Enhancing flows can get difficult, so it helps to reap the benefits of as a lot display screen actual property as doable. With the adaptive layouts offered by Jetpack Compose, such because the supporting pane structure, we are able to dynamically adapt the UI based mostly on the machine’s display screen measurement.

new Composition demo app

Processing overview for sooner trim optimizations

Multi-asset video compositor: We’ve added a customized video compositor that demonstrates tips on how to organize enter media objects into totally different layouts, comparable to a 2×2 grid or a picture-in-picture overlay. These compositor settings are utilized to the Composition, and can be utilized each with CompositionPlayer for preview and Transformer for export.

picture-in-picture video overlay in the Composition demo app

Image-in-picture video overlay within the Composition demo app

Get began with Media3 1.8.0

Please get in contact by way of the Media3 problem Tracker in case you run into any bugs, or when you have questions or function requests. We look ahead to listening to from you!

LEAVE A REPLY

Please enter your comment!
Please enter your name here