Skip to content

Drop video track for HLS streams with separate audio when nothing is on screen - #6439

Draft
joashrajin wants to merge 4 commits into
mainfrom
enhancement/hls-drop-video-without-surface
Draft

joashrajin wants to merge 4 commits into
mainfrom
enhancement/hls-drop-video-without-surface

Conversation

@joashrajin

@joashrajin joashrajin commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

When playing an HLS podcast stream that has a separate audio rendition, the player now stops downloading and decoding video whenever no video surface is on screen, and restores video as soon as the video view returns.

Previously, all HLS streams were exempted from background video track disabling because muxed HLS streams carry audio inside the video segments and cannot play audio if video is disabled. However, streams published with independent audio renditions (such as podcast:alternateEnclosure HLS streams) ended up fetching full video (e.g., 1080p) even during background or screen-off listening.

In Media3, muxed HLS audio tracks always set Format.primaryTrackGroupId to their parent video track group, whereas independent audio renditions (#EXT-X-MEDIA:TYPE=AUDIO with a URI) have primaryTrackGroupId == null. SimplePlayer now checks hasIndependentAudioTrack(tracks) via currentTracks:

  • When the selected audio track in an HLS stream has primaryTrackGroupId == null, shouldDisableVideoTrack disables C.TRACK_TYPE_VIDEO after the existing 10-second VIDEO_TRACK_DISABLE_GRACE_MS grace period when no surface is attached (both on startup without a surface and after surface detach, giving the UI time to mount VideoView without flushing buffered audio) and re-enables it when a surface attaches.
  • When the selected audio track is muxed into video (primaryTrackGroupId != null), the video track stays enabled as before so audio playback is unaffected and background listeners are never silently switched to an alternate-language or audio-description rendition.
  • applyVideoTrackSelection also skips redundant parameter updates when the video disabled state is unchanged and avoids reading stale tracks during prepare().

Fixes #6365

Testing Instructions

  1. Enable HLS streaming if behind the HLS_STREAMING feature flag, and play an episode with an HLS stream that has a separate audio rendition (e.g., a Buzzsprout podcast:alternateEnclosure HLS stream).
  2. Confirm video renders normally while the player screen is open (and in PiP) with no startup audio stall.
  3. Background the app, collapse the player, or lock the screen, and wait >10 seconds. Verify audio continues playing cleanly and network inspection / CDN logs show video segments are no longer being fetched (only audio segments).
  4. Return to the player screen / video view and verify video resumes. Known trade-off: re-enabling video makes Media3 reset the separate audio rendition's buffer, so after more than 10 seconds in the background a brief audio hiccup/rebuffer and a short black frame until the next video segment loads are expected (the same trade-off accepted for progressive video in Skip background video decoding to fix stuttering at high playback speeds #5707). Please check that this is acceptable on device.
  5. Start playback of the same HLS episode while the player is collapsed / without a video surface attached, wait >10 seconds, and verify video segments stop being fetched (only audio segments).
  6. Play a muxed HLS stream (audio muxed into video, no separate audio rendition) and confirm audio continues playing cleanly in the background without interruption.
  7. Run unit tests: ./gradlew :modules:services:repositories:testDebugUnitTest --tests "au.com.shiftyjelly.pocketcasts.repositories.playback.VideoTrackSelectionTest".

Screenshots or Screencast

Not applicable (no UI changes).

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the Event Horizon schema to reflect any new or changed analytics.

I have tested any UI changes...

  • with different themes
  • with a landscape orientation
  • with the device set to have a large display and font size
  • for accessibility with TalkBack

@joashrajin joashrajin added [Type] Enhancement Improve an existing feature. [Area] Playback Episode playback issue labels Nov 22, 2026
@joashrajin joashrajin added this to the 8.26 milestone Nov 22, 2026
@claude

claude Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @joashrajin's task in 2m 9s —— View job


Checking primaryTrackGroupId is the right signal: in Media3 1.11.1, only muxed HLS audio is tagged with the main wrapper's id. The one problem is the new disable-on-track-resolution path. It runs before the player UI has mounted a video surface, so playback started with the full player open goes through a disable/re-enable cycle that flushes the audio buffer. Using the existing grace period for that path should fix it.

Blocking

  • modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/SimplePlayer.kt:275: Starting an HLS episode with a separate audio rendition while the full player is open now briefly stalls audio and delays video. onTracksChanged disables video before VideoView exists, since the view only mounts once streamVideoState becomes HasVideo. When the surface then attaches and video is re-enabled, the audio rendition's buffer is force-reset. Fix: schedule the grace-period disable (scheduleVideoTrackDisable()) here instead of disabling immediately. Drop video track for HLS streams with separate audio when nothing is on screen #6439 (comment)

Non-blocking

  • modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/SimplePlayer.kt:512: On streams that have muxed audio plus a URI audio rendition (e.g. an alternate language), disabling video makes the selector switch to the rendition, so background listeners can silently hear a different audio track. Fix: only treat the stream as independent when the selected audio group has primaryTrackGroupId == null. Drop video track for HLS streams with separate audio when nothing is on screen #6439 (comment)

@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot wpmobilebot modified the milestones: 8.26, 8.27 Nov 23, 2026
@wpmobilebot

Copy link
Copy Markdown
Collaborator

Version 8.26 has now entered code-freeze, so the milestone of this PR has been updated to 8.27.

@joashrajin joashrajin self-assigned this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Playback Episode playback issue [Type] Enhancement Improve an existing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let HLS streams drop video when nothing is on screen

3 participants