Repository navigation
feat(android): support Media3 1.9 in the load control and re-enable bufferingStrategy - #5099
Merged
Merged
Conversation
mziolkowskii
force-pushed
the
fix/android-media3-1.9-load-control
branch
from
September 14, 2026 18:34
3c5713e to
f3666b6
Compare
mziolkowskii
marked this pull request as draft
September 14, 2026 18:45
mziolkowskii
marked this pull request as ready for review
September 15, 2026 05:35
RNVLoadControl extended DefaultLoadControl and called its 9-argument protected constructor, which Media3 1.9 removed. Apps that resolve Media3 1.9, for example with react-native-vision-camera v5, which pulls it in through CameraX, crashed with NoSuchMethodError as soon as a player was created. Build a plain DefaultLoadControl with its Builder, with the same buffer settings. The Builder API is the same in Media3 1.8, 1.9 and 1.10. The subclass only overrode shouldContinueLoading(long, long, float) for bufferingStrategy, and ExoPlayer has not called that overload since Media3 1.4, so the override was unreachable and is removed. bufferingStrategy keeps behaving as it has since 6.6.0; making it work again is a separate change. Fixes #4900
mziolkowskii
force-pushed
the
fix/android-media3-1.9-load-control
branch
from
September 15, 2026 14:46
f3666b6 to
4d5d505
Compare
* fix(android): apply bufferingStrategy again bufferingStrategy was implemented in DefaultLoadControl's shouldContinueLoading(long, long, float) overload. ExoPlayer has only called shouldContinueLoading(Parameters) since Media3 1.4, so from 6.6.0 on DisableBuffering and DependingOnMemory behaved like Default, and the bufferConfig fields only that logic reads, maxHeapAllocationPercent and minBufferMemoryReservePercent, had no effect either. RNVLoadControl now implements LoadControl, applies the strategy in shouldContinueLoading(Parameters) and forwards everything else to a DefaultLoadControl built by buildLoadControl. It forwards only methods whose signatures are the same in Media3 1.8 through 1.10, and declares both getAllocator() variants so it compiles against either. The minimum memory reserve was computed as (long) minBufferMemoryReservePercent * maxMemory, which casts the 0-1 percentage to 0 before multiplying, so the reserve check never triggered. The cast now applies to the product. * fix(android): keep DefaultLoadControl's byte limit on Media3 1.9+ Media3 1.9+ counts buffered bytes per player only through the allocator DefaultLoadControl returns from getAllocator(PlayerId). Handing out the raw allocator left that count at zero, so the byte limit never triggered and only maxBufferMs bounded the buffer. Forward getAllocator(PlayerId) to DefaultLoadControl through reflection, resolved once per load control and matched by signature so R8 renaming does not break it.
…iled allocator lookup source and bufferingStrategy are written from the UI thread and, now that the buffering strategy is applied in shouldContinueLoading(Parameters), read from the playback thread. Mark both volatile so a prop change is not missed there. getAllocator(PlayerId) is only reached on a runtime that calls the PlayerId overload, so a null reflection lookup there means DefaultLoadControl's buffered byte limit is inactive. Log that once instead of falling back silently. Also name the one LoadControl method the wrapper does not forward: shouldContinuePreloading takes a PlayerId in 1.9+ but not in 1.8, so no single declaration compiles against both.
moskalakamil
approved these changes
Sep 17, 2026
fnwk
approved these changes
Sep 17, 2026
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
Stops react-native-video 6 from crashing on Android in apps that resolve Media3 1.9, which is the case with react-native-vision-camera v5, and makes the
bufferingStrategyprop work again.Fixes #4900. Includes #5100, merged into this branch.
Motivation
The crash.
RNVLoadControlextendedDefaultLoadControland called its 9-argument protected constructor. Media3 1.9 removed that constructor.react-native-vision-camera 5 depends on CameraX
camera-video:1.7.0-alpha01, which requiresmedia3-muxer/media3-container1.9.0. Media3's version alignment then resolvesmedia3-exoplayerto 1.9.0 for the whole app, while react-native-video still compiles against its own 1.8.0. The player crashes on creation:The dead prop.
bufferingStrategywas implemented inshouldContinueLoading(long, long, float). ExoPlayer has only calledshouldContinueLoading(Parameters)since Media3 1.4, so from 6.6.0 onDisableBufferingandDependingOnMemorybehaved likeDefault, and the twobufferConfigfields only that logic reads —maxHeapAllocationPercentandminBufferMemoryReservePercent— had no effect either.Changes
buildLoadControlbuilds aDefaultLoadControlthroughDefaultLoadControl.Builderinstead of the removed constructor, with the same settings as before: buffer durations and back buffer frombufferConfig,prioritizeTimeOverSizeThresholds = true, and the Builder's defaults for the allocator andtargetBufferBytes(identical to the values the old code passed explicitly). The Builder API is unchanged across Media3 1.8, 1.9 and 1.10.RNVLoadControlnow implementsLoadControlinstead of extendingDefaultLoadControl. It appliesbufferingStrategyinshouldContinueLoading(Parameters)— the overload ExoPlayer actually calls — and forwards everything else to theDefaultLoadControlfrombuildLoadControl. It forwards only methods whose descriptors are identical in Media3 1.8 through 1.10, and declares bothgetAllocator()andgetAllocator(PlayerId)so it satisfies the interface on either.getAllocator(PlayerId)forwards toDefaultLoadControlby reflection. On 1.9+DefaultLoadControlcounts buffered bytes per player only through the allocator it hands out there, so returning the raw allocator would silently disable its byte limit. The method does not exist in the Media3 this library compiles against, hence the reflection; it is matched by signature so R8 renaming does not break it, and falls back to the raw allocator with a warning.(long) minBufferMemoryReservePercent * maxMemory, which truncates the 0–1 percentage to0before multiplying, so the reserve check never fired. The cast now applies to the product.sourceandbufferingStrategyarevolatile: they are written from the UI thread and, now that the strategy is live, read from the playback thread.Behavior change
bufferingStrategystarts taking effect again for apps that set it. In particularDisableBufferingnow really stops loading, where for the last several minor versions it did nothing. This is why the PR is typedfeatrather thanfix— it needs a minor bump, not a patch.shouldContinuePreloadingis deliberately not forwarded: it takes aPlayerIdin 1.9+ but not in 1.8, so no single declaration compiles against both. ExoPlayer only calls it once a preload configuration is set, which nothing in this library does.Test plan
The setup from the issue: a new React Native 0.84.0 app (new architecture) with
react-native-vision-camera@5.0.9,react-native-nitro-modules@0.35.6andreact-native-nitro-image@0.14.0, rendering a<Video>and a<Camera>on the same screen. Gradle resolvesmedia3-exoplayerto 1.9.0 for the app while react-native-video compiles against 1.8.0. Release build on Android emulators (API 34 and API 37, arm64):NoSuchMethodErrorabove, same line numbers as in the issueAndroidXMedia3/1.9.0; camera session and preview start; video loads andonProgresskeeps firingMedia3 1.8.0: the same app with every Media3 artifact forced to 1.8.0 (react-native-video's default): this branch plays (
AndroidXMedia3/1.8.0,onProgresskeeps firing, normal buffering).Compile and link checks: the load control code compiles against Media3 1.8.0, 1.9.4 and 1.10.1, and for every compile/runtime pair of those versions each Media3 method it references exists with the same descriptor. The same check on the original code reports the missing constructor.
LoadControl's only abstract method isgetAllocator()in 1.8 andgetAllocator(PlayerId)in 1.9+, and declaring both satisfies either runtime.bufferingStrategy:DisableBufferingandDependingOnMemorywere verified to reachshouldContinueLoading(Parameters)again.Not tested: iOS (not affected), physical camera hardware.