We additionally added caching and reminiscence administration enhancements to PreloadManager, and offered a number of new ExoPlayer, Transformer and MediaSession simplifications.
This launch additionally provides you the primary experimental entry to CompositionPlayer to preview media edits.
Learn on to seek out out extra, and as at all times please try the total launch notes for a complete overview of modifications on this launch.
Extract metadata and frames outdoors of playback
There are lots of instances the place you need to examine media with out beginning a playback. For instance, you may need to detect which codecs it accommodates 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 alternative for the Android platform MediaExtractor class, to get detailed details about samples within the file.
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 choose to construct your individual UI model, you should use the constructing blocks that deal with all of the replace and connection logic, so that you solely want to focus on designing the UI aspect. Please try our prolonged information pages for the Compose UI modules.
We’re additionally nonetheless engaged on much more Compose parts, like a prebuilt search bar, an entire out-of-the-box alternative 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) } } }
Easy Compose participant UI with out-of-the-box components
Mechanically deal with transitions between Solid and native playbacks
The CastPlayer within the media3-cast module has been rewritten to mechanically 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 executed!
// 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() }
New CastPlayer integration in Media3 session demo app
Constant AV1 playback with the rewritten extension based mostly on dav1d
The 1.9.0 launch accommodates a totally rewritten AV1 extension module based mostly on the favored dav1d library.
As with all extension decoder modules, please be aware that it requires constructing from supply to bundle the related native code appropriately. Bundling a decoder offers consistency and format help throughout all gadgets, however as a result of it runs the decoding in your course of, it is best fitted to content material you may belief.
Combine caching and reminiscence administration into PreloadManager
We made our PreloadManager even higher as nicely. It already enabled you to preload media into reminiscence outdoors 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 chance preloading an excessive amount of. So with Media3 1.9.0, we added two options that makes this so much simpler and extra steady:
Caching help – When defining how far to preload, now you can select PreloadStatus.specifiedRangeCached(0, 5000) as a goal state for preloaded gadgets. This may add the required vary to your cache on disk as an alternative of loading the info to reminiscence. With this, you may present a a lot bigger vary of things for preloading as those additional away from the present merchandise not have to occupy reminiscence. Word that this requires setting a Cache in DefaultPreloadManager.Builder.
Automated reminiscence administration – We additionally up to date our LoadControl interface to higher 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 mechanically cease preloading as soon as the restrict is reached, and mechanically releases reminiscence of decrease precedence gadgets if required.
Depend on new simplified default behaviors in ExoPlayer
As at all times, we added a number of incremental enhancements to ExoPlayer as nicely. 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 retaining monitor of it your self.
Caught participant detection – In some uncommon instances the participant can get caught in a buffering or enjoying state with out making any progress, for instance, on account of codec points or misconfigurations. Your customers will likely be aggravated, however you by no means see these points in your analytics! To make this extra apparent, the participant now experiences a StuckPlayerException when it detects a caught state.
Wakelock by default – The wake lock administration was beforehand opt-in, leading to exhausting to seek out edge instances the place playback progress will 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 also can 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 exhausting 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 should 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()
))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 accessible for experimentation, however remains to be underneath improvement.
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 start out utilizing CompositionPlayer and share your suggestions, and preserve an eye fixed out for forthcoming posts and updates to the documentation for extra particulars.
InAppMuxer as a default muxer in Transformer
New pace adjustment APIs
The 1.9.0 launch simplifies pace changes APIs for media enhancing. We have launched new strategies straight on EditedMediaItem.Builder to manage pace, making the API extra intuitive. Now you can change the pace of a clip by calling setSpeed(SpeedProvider supplier) on the EditedMediaItem.Builder:
val speedProvider = object : SpeedProvider { override enjoyable getSpeed(presentationTimeUs: Lengthy): Float { return pace } 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 monitor varieties for EditedMediaItemSequence
That is executed through a brand new EditedMediaItemSequence.Builder constructor that accepts a set of monitor varieties (e.g., C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_VIDEO).
To simplify creation, we have added new static comfort strategies:
EditedMediaItemSequence.withAudioFrom(Checklist<EditedMediaItem>)
EditedMediaItemSequence.withVideoFrom(Checklist<EditedMediaItem>)
EditedMediaItemSequence.withAudioAndVideoFrom(Checklist<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 through the Media3 challenge Tracker should you run into any bugs, or you probably have questions or function requests. We sit up for listening to from you!
