Android Builders Weblog: Media3 1.9.0


Media3 1.9.0 is out! Apart from the standard bug fixes and efficiency enhancements, the newest launch additionally incorporates 4 new or largely rewritten modules:

We additionally added caching and reminiscence administration enhancements to PreloadManager, and offered a number of new ExoPlayer, Transformer and MediaSession simplifications. 

This launch additionally offers you the primary experimental entry to CompositionPlayer to preview media edits.  


Learn on to seek out out extra, and as all the time please try the total launch notes for a complete overview of modifications on this launch.

Extract metadata and frames exterior of playback

There are various instances the place you wish to examine media with out beginning a playback. For instance, you would possibly wish to detect which codecs it incorporates or what its length is, or to retrieve thumbnails.

The brand new media3-inspector module combines all utilities to examine media with out playback in a single place:

  • MetadataRetriever to learn length, format and static metadata from a MediaItem.

  • FrameExtractor to get frames or thumbnails from an merchandise. 

  • MediaExtractorCompat as a direct substitute for the Android platform MediaExtractor class, to get detailed details about samples within the file.

MetadataRetriever and FrameExtractor observe a easy AutoCloseable sample. Take a look at our new information pages for extra particulars.
droop enjoyable extractThumbnail(mediaItem: MediaItem) {
  FrameExtractor.Builder(context, mediaItem).construct().use {
    val thumbnail = frameExtractor.getThumbnail().await()
  } 
}

Construct a fundamental Material3 Compose Media UI in just some steps

In earlier releases we began offering connector code between Compose UI components and your Participant occasion. With Media3 1.9.0, we added a brand new module media3-ui-compose-material3 with fully-styled Material3 buttons and content material components. They can help you construct a media UI in just some steps, whereas offering all the flexibleness to customise model. In case you want to construct your individual UI model, you need to use the constructing blocks that care for all of the replace and connection logic, so that you solely want to focus on designing the UI factor. Please try our prolonged information pages for the Compose UI modules.


We’re additionally nonetheless engaged on much more Compose elements, like a prebuilt search bar, an entire out-of-the-box substitute for PlayerView, in addition to subtitle and advert integration.

@Composable
enjoyable SimplePlayerUI(participant: Participant, modifier: Modifier = Modifier) {
  Column(modifier) {
    ContentFrame(participant)  // Video floor and shutter logic
    Row (Modifier.align(Alignment.CenterHorizontally)) {                 
      SeekBackButton(participant)   // Easy controls
      PlayPauseButton(participant)
      SeekForwardButton(participant)
    }
  }
}

Android Builders Weblog: Media3 1.9.0 1

Easy Compose participant UI with out-of-the-box components

Routinely deal with transitions between Solid and native playbacks

The CastPlayer within the media3-cast module has been rewritten to robotically deal with transitions between native playback (for instance with ExoPlayer) and distant Solid playback.

Once you arrange your MediaSession, merely construct a CastPlayer round your ExoPlayer and add a MediaRouteButton to your UI and also you’re finished!

// MediaSession setup with CastPlayer 
val exoPlayer = ExoPlayer.Builder(context).construct()
val castPlayer = CastPlayer.Builder(context).setLocalPlayer(exoPlayer).construct()
val session = MediaSession.Builder(context, participant)
// MediaRouteButton in UI 
@Composable enjoyable UIWithMediaRouteButton() {
  MediaRouteButton()
}

Android Builders Weblog: Media3 1.9.0 2

New CastPlayer integration in Media3 session demo app

Constant AV1 playback with the rewritten extension primarily based on dav1d

The 1.9.0 launch incorporates a totally rewritten AV1 extension module primarily based on the favored dav1d library.

As with all extension decoder modules, please notice that it requires constructing from supply to bundle the related native code appropriately. Bundling a decoder offers consistency and format help throughout all units, however as a result of it runs the decoding in your course of, it is best suited to content material you possibly can belief. 

Combine caching and reminiscence administration into PreloadManager

We made our PreloadManager even higher as properly. It already enabled you to preload media into reminiscence exterior of playback after which seamlessly hand it over to a participant when wanted. Though fairly performant, you continue to needed to be cautious to not exceed reminiscence limits by by accident preloading an excessive amount of. So with Media3 1.9.0, we added two options that makes this so much simpler and extra steady:

  1. Caching help – When defining how far to preload, now you can select PreloadStatus.specifiedRangeCached(0, 5000) as a goal state for preloaded gadgets. This can add the desired vary to your cache on disk as an alternative of loading the info to reminiscence. With this, you possibly can present a a lot bigger vary of things for preloading as those additional away from the present merchandise now not must occupy reminiscence. Be aware that this requires setting a Cache in DefaultPreloadManager.Builder.

  2. Automated reminiscence administration – We additionally up to date our LoadControl interface to raised deal with the preload case so that you at the moment are capable of set an express higher reminiscence restrict for all preloaded gadgets in reminiscence. It is 144 MB by default, and you’ll configure the restrict in DefaultLoadControl.Builder. The DefaultPreloadManager will robotically cease preloading as soon as the restrict is reached, and robotically releases reminiscence of decrease precedence gadgets if required.

Depend on new simplified default behaviors in ExoPlayer

As all the time, we added plenty of incremental enhancements to ExoPlayer as properly. To call just some:

  • Mute and unmute – We already had a setVolume technique, however have now added the comfort mute and unmute strategies to simply restore the earlier quantity with out holding observe of it your self.

  • Caught participant detection – In some uncommon instances the participant can get caught in a buffering or taking part in state with out making any progress, for instance, on account of codec points or misconfigurations. Your customers will likely be irritated, however you by no means see these points in your analytics! To make this extra apparent, the participant now stories a StuckPlayerException when it detects a caught state.

  • Wakelock by default – The wake lock administration was beforehand opt-in, leading to laborious to seek out edge instances the place playback progress could be delayed so much when working within the background. Now this function is opt-out, so you do not have to fret about it and can even take away all handbook wake lock dealing with round playback.

  • Simplified setting for CC button logic Altering TrackSelectionParameters to say “flip subtitles on/off” was surprisingly laborious to get proper, so we added a easy boolean selectTextByDefault choice for this use case.

Simplify your media button preferences in MediaSession

Till now, defining your preferences for which buttons ought to present up within the media notification drawer on Android Auto or WearOS required defining customized instructions and buttons, even in case you merely needed to set off a typical participant technique.

Media3 1.9.0 has new performance to make this so much easier – now you can outline your media button preferences with a typical participant command, requiring no customized command dealing with in any respect.

session.setMediaButtonPreferences(listOf(
    CommandButton.Builder(CommandButton.ICON_FAST_FORWARD) // select an icon
      .setDisplayName(R.string.skip_forward)
      .setPlayerCommand(Participant.COMMAND_SEEK_FORWARD) // select an motion 
      .construct()
))

Android Builders Weblog: Media3 1.9.0 3

Media button preferences with quick ahead button

CompositionPlayer for real-time preview

The 1.9.0 launch introduces CompositionPlayer underneath a brand new @ExperimentalApi annotation. The annotation signifies that it’s obtainable for experimentation, however remains to be underneath growth. 

CompositionPlayer is a brand new element within the Media3 enhancing APIs designed for real-time preview of media edits. Constructed upon the acquainted Media3 Participant interface, CompositionPlayer permits customers to see their modifications in motion earlier than committing to the export course of. It makes use of the identical Composition object that you’d go to Transformer for exporting, streamlining the enhancing workflow by unifying the info mannequin for preview and export.

We encourage you to begin utilizing CompositionPlayer and share your suggestions, and hold an eye fixed out for forthcoming posts and updates to the documentation for extra particulars.

InAppMuxer as a default muxer in Transformer

Transformer now makes use of InAppMp4Muxer because the default muxer for writing media container recordsdata. Internally, InAppMp4Muxer is dependent upon the Media3 Muxer module, offering constant behaviour throughout all API variations. 

Be aware that whereas Transformer now not makes use of the Android platform’s MediaMuxer by default, you possibly can nonetheless present FrameworkMuxer.Manufacturing unit by way of setMuxerFactory in case your use case requires it.

New velocity adjustment APIs

The 1.9.0 launch simplifies velocity changes APIs for media enhancing. We have launched new strategies straight on EditedMediaItem.Builder to manage velocity, making the API extra intuitive. Now you can change the velocity of a clip by calling setSpeed(SpeedProvider supplier) on the EditedMediaItem.Builder:

val speedProvider = object : SpeedProvider {
    override enjoyable getSpeed(presentationTimeUs: Lengthy): Float {
        return velocity
    }

    override enjoyable getNextSpeedChangeTimeUs(timeUs: Lengthy): Lengthy {
        return C.TIME_UNSET
    }
}

EditedMediaItem speedEffectItem = EditedMediaItem.Builder(mediaItem)
    .setSpeed(speedProvider)
    .construct()

This new method replaces the earlier technique of utilizing Results#createExperimentalSpeedChangingEffects(), which we have deprecated and can take away in a future launch.

Introducing observe varieties for EditedMediaItemSequence

Within the 1.9.0 launch, EditedMediaItemSequence requires specifying desired output observe varieties throughout sequence creation. This variation ensures observe dealing with is extra express and strong throughout the whole Composition.

That is finished by way of a brand new EditedMediaItemSequence.Builder constructor that accepts a set of observe varieties (e.g., C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_VIDEO). 

To simplify creation, we have added new static comfort strategies:

  • EditedMediaItemSequence.withAudioFrom(Record<EditedMediaItem>)

  • EditedMediaItemSequence.withVideoFrom(Record<EditedMediaItem>)

  • EditedMediaItemSequence.withAudioAndVideoFrom(Record<EditedMediaItem>)

We encourage you emigrate to the brand new constructor or the comfort strategies for clearer and extra dependable sequence definitions.

Instance of making a video-only sequence:

EditedMediaItemSequence videoOnlySequence =
    EditedMediaItemSequence.Builder(setOf(C.TRACK_TYPE_VIDEO))
        .addItem(editedMediaItem)
        .construct()

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

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles