Media2 snippet migration - #1114
Open
barbaralaw wants to merge 3 commits into
Open
barbaralaw wants to merge 3 commits into
barbaralaw wants to merge 3 commits into
Conversation
Alphabetize :media dependencies, rename MediaProjection.kt, replace the spatial-audio ellipsis sandwich with // ..., and fix ViewModel comment / HDR buffer indent plus Surface imports.
barbaralaw
force-pushed
the
media2-snippet-migration
branch
from
September 17, 2026 22:31
60e9422 to
4359abc
Compare
barbaralaw
marked this pull request as ready for review
September 18, 2026 15:18
|
Here is the summary of changes. You are about to add 19 region tags.
This comment is generated by snippet-bot.
|
kkuan2011
reviewed
Sep 19, 2026
| } | ||
| // [END android_media_ai_enhancement_bitmap_viewmodel] | ||
|
|
||
| // Shims for Media Enhancement API types if not provided by standalone SDK |
Contributor
There was a problem hiding this comment.
Are these classes provided by an existing google library? If so, could we use the library instead of defining shims?
| import android.widget.ImageView | ||
| import androidx.fragment.app.Fragment | ||
|
|
||
| class UltraHdrDisplayFragment : Fragment() { |
Contributor
There was a problem hiding this comment.
If this is more of a Fragment snippet, I'm wondering if we need to migrate this? Is there a compose-version of this code? or is this the only way to do it?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts the Kotlin samples from eight Media guides (AI enhancement, HDR, media projection, spatial audio, and Ultra HDR) into
:mediaas region-tagged source, so the guides can import them instead of hardcoding them.19 snippets across 8 pages. 14 publish exactly what the page shows. 5 differ, listed below with a reason. Small Spotless rewraps (a long call split the same way the formatter always splits it) are not listed. A wrap that changes the shape of the call is listed.
Region tags all begin
android_media_; the tables drop that prefix.How to read the "why" column
// ......, which Kotlin will not compile. The region publishes// ....Per page
1. Understand the media enhancement lifecycle in Bitmap mode
https://developer.android.com/media/ai-enhancement/bitmap-mode-lifecycle
3 snippets, 1 match, 2 differ.
ai_enhancement_bitmap_wrappersthis.createSession(...)insidewithContext { }becomesthis@createSessionAsync.createSession(...)ai_enhancement_bitmap_viewmodelMatching as published:
ai_enhancement_bitmap_initialize_engine.The enhancement client types used by this and the Bitmap/Surface/get-started pages are compile-only shims in
:media. The get-started page’s Gradle coordinate (play-services-media-effect-enhancement) was left hardcoded.2. Get started with Media Enhancement APIs
https://developer.android.com/media/ai-enhancement/get-started
1 snippet, matches as published:
ai_enhancement_get_started_checks.3. Understand the media enhancement lifecycle in Surface mode
https://developer.android.com/media/ai-enhancement/surface-mode-lifecycle
2 snippets, all 2 match as published:
ai_enhancement_surface_initialize_engine,ai_enhancement_surface_snapshot.4. Color correct with look-up tables (LUTs)
https://developer.android.com/media/grow/hdr-lut
1 snippet, matches as published:
hdr_lut_apply.5. HDR video playback
https://developer.android.com/media/grow/hdr-playback
2 snippets, 1 match, 1 differ.
hdr_playback_mediacodecval list = MediaCodecList(...) var format = MediaFormat() …onto two statementsMatching as published:
hdr_playback_check_support.6. Media projection
https://developer.android.com/media/grow/media-projection
3 snippets, 2 match, 1 differ.
projection_window_context_metricscreateWindowContext(context.display!!, TYPE_APPLICATION, null)is split socontext.display!!and the closing)sit on their own linesMatching as published:
projection_start,projection_virtual_display.7. Spatial Audio
https://developer.android.com/media/grow/spatial-audio
6 snippets, 5 match, 1 differ.
spatial_audio_disable_channel_constraints_selector...becomes// ...// ...Matching as published:
spatial_audio_get_spatializer,spatial_audio_disable_channel_constraints_player,spatial_audio_set_max_channels,spatial_audio_max_output_channels,spatial_audio_audio_format.8. Display Ultra HDR images
https://developer.android.com/media/grow/ultra-hdr/display
1 snippet, matches as published:
ultra_hdr_display_window_color_mode.Not extracted
Kotlin only. HDR LUT, HDR playback, media projection, spatial audio, and Ultra HDR each have Java twins left for the page edit that retires them. Get started also leaves two Gradle
dependenciesblocks and the native-library manifest. Media projection leaves the foreground-service manifest. Spatial audio leaves the dumpsys/log “Test spatial audio” output.Live snippet fixes this surfaced
val list = MediaCodecList(...) var format = MediaFormat() /* media format from the container */;), which is not valid Kotlin. The region publishes them as separate statements.this.createSession(...)sits insidewithContext(Dispatchers.Main) { }, sothisis theCoroutineScopeand the call does not compile. The region keeps the Main hop (the ViewModel sample calls this wrapper fromDispatchers.IO) and publishesthis@createSessionAsync.createSession(...)....betweenDefaultTrackSelectorsetup andbuildUponParametersis not valid Kotlin. The region publishes// ....Verification
./gradlew :media:compileDebugKotlin— passes./gradlew :media:lintDebug— passes./gradlew :media:spotlessApply— run; Kotlin in:mediais already clean. Spotless skippedmedia/build.gradle.kts(formatter does not converge on that file).