[video_player_android] allow supplying a custom VideoAsset - #12491
Open
a1rwulf wants to merge 1 commit into
Open
[video_player_android] allow supplying a custom VideoAsset#12491a1rwulf wants to merge 1 commit into
a1rwulf 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.
Contributor
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; |
Contributor
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.
Suggested change
| private static @Nullable VideoAssetProvider videoAssetProvider; | |
| private static volatile @Nullable VideoAssetProvider videoAssetProvider; |
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.
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