Skip to content

[video_player_android] allow supplying a custom VideoAsset - #12491

Open
a1rwulf wants to merge 1 commit into
flutter:mainfrom
a1rwulf:upstream_video-asset-provider-v2
Open

[video_player_android] allow supplying a custom VideoAsset#12491
a1rwulf wants to merge 1 commit into
flutter:mainfrom
a1rwulf:upstream_video-asset-provider-v2

Conversation

@a1rwulf

@a1rwulf a1rwulf commented Aug 17, 2026

Copy link
Copy Markdown

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

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-assist bot 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

  1. 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

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant