How Did We Encounter the ExoPlayer Subtitles Issue in Jetpack Compose?
During a recent project for a global e-learning and EdTech platform, we were tasked with modernizing their mobile application. The core feature of the platform is a highly customizable video player that supports multiple video qualities, playback speeds and dynamic multi-language subtitles. To achieve a highly reactive UI, we decided to migrate the entire video playback screen to Jetpack Compose while utilizing AndroidX Media3 (ExoPlayer) for the underlying media engine.
While video playback and basic controls worked perfectly, we encountered a significant roadblock: subtitles simply refused to display. We were fetching the subtitle files (VTT formats), building the MediaItem.SubtitleConfiguration and injecting them into the player. Our logs clearly showed that the ExoPlayer was parsing the tracks and firing the onCues callbacks with the correct text, but the Jetpack Compose UI remained completely blank.
In a production environment where accessibility and multi-lingual support are non-negotiable, a failing subtitle rendering engine is a critical blocker. This challenge required us to dive deep into how ExoPlayer manages track selection parameters and how imperative Android Views like SubtitleView interact with Jetpack Compose’s declarative recomposition cycles. We are sharing this technical breakdown so other teams can avoid these architectural pitfalls. If you are looking to scale your media engineering efforts, it often helps to hire software developer teams with deep domain expertise in video streaming and Compose interoperability.
What Causes ExoPlayer Subtitles to Fail in a Jetpack Compose Architecture?
In a traditional XML-based Android UI, ExoPlayer’s PlayerView handles the video surface, player controls and the SubtitleView automatically. However, when building a heavily customized player in Jetpack Compose, engineers often decouple these components. They create a dedicated surface for the video and attempt to manage the subtitles separately by hoisting the subtitle cues into Compose state.
In our business use case, the UI demanded custom positioning for subtitles to avoid overlapping with interactive on-screen elements. We introduced a standalone SubtitleView wrapped inside an AndroidView. The issue surfaced right at the intersection of ExoPlayer’s track selection and Compose’s state management. We were injecting the subtitle files into the MediaItem correctly, but dynamically switching between languages failed to render text.
What Went Wrong with the Dynamic Subtitle Track Selection?
Our initial diagnosis revealed three distinct architectural oversights in the implementation:
- Re-rendering the entire MediaItem: Initially, the logic reloaded the entire video stream whenever a user switched subtitle languages. This caused buffering and disrupted the user experience. We shifted to loading all subtitle configurations at once and switching tracks dynamically, but this exposed the next issue.
- Track ID Mismatch: When applying overrides via
TrackSelectionParameters, the system relies on exact ID matching. We were assigning the subtitle URL as the ID during configuration, but during track selection, thegetFormat(0).idcomparison was failing due to nullability or asynchronous state mismatches in thecurrentTrackslist. - SubtitleView Lifecycle Quirk: The
SubtitleViewinside theAndroidViewwas receiving thecurrentCuesupdates via theupdateblock, but because of missing layout parameters and styling defaults within the Compose wrapper, the view measured itself at zero height or rendered the text transparently against the video surface.
How Did We Approach Solving the ExoPlayer Subtitle Synchronization?
To resolve the issue without compromising performance, we evaluated several solutions before landing on the final implementation.
Should We Revert to the Default PlayerView?
The simplest solution was to abandon the decoupled architecture and wrap the standard Media3 PlayerView inside an AndroidView, calling setUseController(false). This handles subtitles perfectly natively. However, we rejected this approach because the EdTech platform required highly custom gesture overlays and dynamic subtitle positioning based on whether the custom controls were visible. We needed granular control over the UI.
Could We Force Recomposition on Track Changes?
We considered forcing a complete recomposition of the AndroidView wrapper by tying the selectedSubtitles state directly to the view’s key. While this forced the SubtitleView to redraw, it was incredibly inefficient and caused visual flickering during subtitle transitions.
How About Decoupled State Management with Synchronized Overrides?
We chose to keep the decoupled architecture but fix the underlying state bridge. We would manage the currentCues via a correctly scoped DisposableEffect, ensure the SubtitleView was properly styled upon initialization and strictly handle the TrackSelectionParameters using Media3’s recommended override builder. When you hire android developers for media applications, ensuring they understand this level of state synchronization is crucial for delivering smooth user experiences.
How to Properly Implement Dynamic Subtitles with ExoPlayer in Jetpack Compose?
Here is the sanitized and corrected implementation. This solution ensures that track selections are handled gracefully and the standalone SubtitleView reacts correctly to Compose state changes.
// 1. State Management for Cues and Tracks
var currentCues by remember { mutableStateOf<List<Cue>>(emptyList()) }
var currentTracks by remember { mutableStateOf(Tracks.EMPTY) }
// 2. Initializing the MediaItem with Subtitles
LaunchedEffect(selectedSource) {
val subtitleConfigs = playerData.subtitles.map { subtitle ->
MediaItem.SubtitleConfiguration.Builder(Uri.parse(subtitle.src))
.setMimeType(MimeTypes.TEXT_VTT)
.setId(subtitle.id) // Use a distinct, stable ID
.setLabel(subtitle.label)
.build()
}
val mediaItem = MediaItem.Builder()
.setUri(selectedSource)
.setSubtitleConfigurations(subtitleConfigs)
.build()
exoPlayer.setMediaItem(mediaItem)
exoPlayer.prepare()
}
// 3. Handling Dynamic Track Selection Safely
LaunchedEffect(selectedSubtitleId, currentTracks) {
val trackSelectionParameters = exoPlayer.trackSelectionParameters.buildUpon()
if (selectedSubtitleId == null) {
// Disable text tracks if none selected
trackSelectionParameters.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, true)
trackSelectionParameters.clearOverridesOfType(C.TRACK_TYPE_TEXT)
} else {
// Enable text tracks and find the exact match
trackSelectionParameters.setTrackTypeDisabled(C.TRACK_TYPE_TEXT, false)
val textTrackGroup = currentTracks.groups.find { group ->
group.type == C.TRACK_TYPE_TEXT &&
group.mediaTrackGroup.getFormat(0).id == selectedSubtitleId
}
textTrackGroup?.let {
trackSelectionParameters.setOverrideForType(
TrackSelectionOverride(it.mediaTrackGroup, 0)
)
}
}
exoPlayer.trackSelectionParameters = trackSelectionParameters.build()
// 4. Bridging ExoPlayer Listeners to Compose State
DisposableEffect(exoPlayer) {
val listener = object : Player.Listener {
override fun onCues(cueGroup: CueGroup) {
currentCues = cueGroup.cues
}
override fun onTracksChanged(tracks: Tracks) {
currentTracks = tracks
}
}
exoPlayer.addListener(listener)
onDispose {
exoPlayer.removeListener(listener)
}
}
// 5. Rendering the UI
Box(modifier = Modifier.fillMaxSize()) {
// Video Surface
AndroidView(
factory = { ctx ->
TextureView(ctx).apply {
exoPlayer.setVideoTextureView(this)
}
},
modifier = Modifier.fillMaxSize()
)
// Decoupled SubtitleView
AndroidView(
factory = { ctx ->
SubtitleView(ctx).apply {
// CRITICAL: Set styling and layout parameters so it draws correctly
setUserDefaultStyle()
setUserDefaultTextSize()
setBottomPaddingFraction(SubtitleView.DEFAULT_BOTTOM_PADDING_FRACTION)
}
},
update = { view ->
// Inject state-hoisted cues safely
view.setCues(currentCues)
},
modifier = Modifier
.fillMaxSize()
// Dynamically adjust padding to avoid overlapping custom controls
.padding(bottom = if (isControlsVisible) 100.dp else 24.dp)
)
}
By enforcing a stable ID matching system and initializing the SubtitleView with default styles before injecting the currentCues, we solved the transparent text issue. State propagation now smoothly updates the view without forcing aggressive recompositions of the video surface.
What Are the Key Lessons for Engineering Teams Building Media Players?
Building resilient media players demands a strong grasp of both the media engine and the UI framework. When companies look to hire app developer to create a mobile app that handles complex media, they should ensure the team understands these core principles:
- Decouple Thoughtfully: Only separate your UI (like
SubtitleView) from the standardPlayerViewif you absolutely need granular control. Standard components handle edge cases you might not anticipate. - Ensure Stable Identifiers: When injecting configurations into
MediaItem, use stable, deterministic IDs. Relying on URLs as IDs can lead to matching failures during track selection if the URI is parsed differently internally. - Initialize AndroidViews Properly: A common Compose pitfall is assuming an
AndroidViewwill automatically size and style itself. Views likeSubtitleViewoften need explicit default styling (setUserDefaultStyle()) to render visible text. - Leverage the TrackSelection Builder: Never mutate track selections directly. Always use
exoPlayer.trackSelectionParameters.buildUpon()to ensure you aren’t wiping out underlying configurations (like audio or video bitrate adaptations). - Prevent Unnecessary Re-buffering: Loading all subtitle configurations at the
MediaItemcreation stage and dynamically selecting them later is significantly more performant than reloading the URI on every language switch.
How Can We Help You Build Robust Media Architectures?
Migrating complex legacy Android components to Jetpack Compose often exposes intricate state synchronization challenges. Solving these architectural issues requires a deep understanding of memory management, UI lifecycles and underlying framework internals. At WeblineGlobal, we provide pre-vetted remote engineering teams that bring enterprise-grade maturity to your mobile architectures. Whether you are building an EdTech video platform or scaling a complex mobile infrastructure, we are here to help. contact us to discuss your engineering needs.
Social Hashtags
#ExoPlayer #JetpackCompose #AndroidMedia3 #AndroidDevelopment #Kotlin #Media3 #AndroidDev #VideoStreaming #MobileAppDevelopment #SoftwareEngineering #EdTech #AndroidDevelopers #WeblineGlobal
Frequently Asked Questions
This usually occurs because the SubtitleView inside an AndroidView wrapper lacks default styling or layout constraints. Calling setUserDefaultStyle() and setUserDefaultTextSize() within the factory block usually resolves this.
Instead of reloading the MediaItem, utilize exoPlayer.trackSelectionParameters. Extract the specific TrackGroup for the desired text format and apply it using setOverrideForType() while ensuring setTrackTypeDisabled(C.TRACK_TYPE_TEXT, false) is set.
If your player UI follows standard layouts, always use the unified PlayerView wrapped in an AndroidView. Only use a standalone SubtitleView if your design requires placing subtitles in unconventional positions or animating them independently of the video surface.
Wrap your Player.Listener inside a DisposableEffect keyed to the exoPlayer instance. This ensures the listener is attached when the player enters the composition and cleanly removed in the onDispose block to prevent memory leaks.
Success Stories That Inspire
See how our team takes complex business challenges and turns them into powerful, scalable digital solutions. From custom software and web applications to automation, integrations, and cloud-ready systems, each project reflects our commitment to innovation, performance, and long-term value.

Asia-Pacific Hospitality Firm Builds Guest Engagement CRM

European Logistics Provider Automated Document Processing



















