[video_player_android] allow supplying a custom VideoAsset - #12491
[video_player_android] allow supplying a custom VideoAsset#12491a1rwulf wants to merge 1 commit into
Conversation
Adds VideoAssetProvider and VideoPlayerPlugin.setVideoAssetProvider, which is consulted before this plugin's own URI handling and may return null to fall through to it. This is the extension point for playback the plugin cannot express itself: reading from a download or HTTP cache, applying a custom DataSource.Factory, or resolving a scheme the plugin does not know about. VideoAsset is already public and already exposes MediaItem and MediaSource.Factory, so this adds no new type surface; it only makes the existing one reachable. Behavior is unchanged when no provider is registered, which the added tests cover alongside the override path.
There was a problem hiding this comment.
Code Review
This pull request introduces VideoAssetProvider and VideoPlayerPlugin.setVideoAssetProvider to the Android video player plugin, enabling custom video asset resolution for URIs. It also adds unit tests to verify this behavior and bumps the package version to 2.13.0. The reviewer recommended marking the static videoAssetProvider field as volatile to ensure thread visibility and prevent stale reads.
| private final VideoPlayerOptions sharedOptions = new VideoPlayerOptions(); | ||
| private long nextPlayerIdentifier = 1; | ||
|
|
||
| private static @Nullable VideoAssetProvider videoAssetProvider; |
There was a problem hiding this comment.
Since videoAssetProvider is a static field that can be set from any thread (e.g., during background initialization or dependency injection) and read on the main thread, it should be marked as volatile to ensure thread visibility and prevent stale reads.
| private static @Nullable VideoAssetProvider videoAssetProvider; | |
| private static volatile @Nullable VideoAssetProvider videoAssetProvider; |
|
Adding @mboetger to review for whether allowing modification of ExoPlayer internals like this is something we want to expose; generally we minimize native hook points as they can significantly reduce our ability to make non-breaking updates in the future.
Adding @bparrishMines to guide the design here if this does move forward. We traditionally do not consider our native plugin code to be a public API surface, and instead consider it equivalent to lib/src/. When we deviate from that we do so in limited and clearly documented ways, and @bparrishMines can point to examples of what that would look like. |
Adds VideoAssetProvider and VideoPlayerPlugin.setVideoAssetProvider, which is consulted before this plugin's own URI handling and may return null to fall through to it.
This is the extension point for playback the plugin cannot express itself: reading from a download or HTTP cache, applying a custom DataSource.Factory, or resolving a scheme the plugin does not know about. VideoAsset is already public and already exposes MediaItem and MediaSource.Factory, so this adds no new type surface; it only makes the existing one reachable.
Behavior is unchanged when no provider is registered, which the added tests cover alongside the override path.
This enables me to publish a companion package to allow downloading of HLS on Android and iOS.
Companion package source:
https://github.com/a1rwulf/video_player_offline
This is an attempt to upstream a fix for:
flutter/flutter#59759
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2