Native crash when switching back to main TS content after HLS ad with custom DataSource
@tianyif is already working on this.
Since Oct 14, 2025.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Hi Media3 team,
I’m experiencing a native crash when switching back to a main TS content after playing an HLS ad. My setup is as follows:
Setup
- I use a custom TunerDataSource that implements a circular buffer and continuously streams TS from a multicast/QAM source.
- Main content is played using this TunerDataSource.
- HLS ads are preloaded and played via a MediaSource switch.
The player flow:
- Main TS content is playing via TunerDataSource ( custom implementation of DataSource).
- Pause main TS, switch to HLS ad (preloaded via preloadManager or even without preloading, direct mediasource switch).
- After ad ends, I switch back to the main TS content.
- If I reuse the previous TunerDataSource for step 3:
- After 3–4 iterations of this ad switch, the app crashes with native SIGSEGV in MediaCodec / codeclooper / faultaddr.
- If I create a fresh TunerDataSource instance for every main content switch: No crash occurs.
My observations:
Crash seems related to ExoPlayer / MediaCodec holding stale native buffer references when the same DataSource is reused after a full media source reset.
Scenario – TS → HLS ad → TS (Direct Switch)
Description: Main content uses a custom TS datasource, switch to an HLS ad, then back to the main TS datasource (letting buffer overwrite happen).
Result: Crash occurs (native crash in MediaCodec_loop / SIGSEGV / fault addr).
Scenario – TS Pause & Resume (Safe Resume)
Description: Main content uses custom TS datasource, pause the player, let the circular buffer fill, then resume playback.
Result: No crash observed.
Conclusion: Buffer overwritten is not causing this crash.
Scenario – TS → PreloadManager Ad → TS
Description: Main content uses custom TS datasource, switch to an ad via PreloadManager, then switch back to main TS datasource.
Result: Crash occurs.
Possibly, Switching between different types of media sources (custom TS ↔ HLS/PreloadManager) is causing native-level crashes.
Questions
- Is this expected behavior in Media3 when switching between different types of media sources (custom TS ↔ HLS)?
- What is the recommended approach to safely reuse a custom TS DataSource across MediaSource switches (TS → HLS → TS) without creating a new instance every time?
- Would you recommend implementing a “reset” mechanism in the custom DataSource, or avoiding prepare() when switching back to the main TS content?
- I want to achieve smooth transitions between main → ad → main content without triggering native crashes. How can this best be handled using Media3?
Any guidance or best practices for handling this scenario would be highly appreciated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.