Skip to content

[video_player] Add opt-in Android renderer options to mitigate MediaCodec initialization failures#11338

Open
maeddin wants to merge 2 commits intoflutter:mainfrom
maeddin:video_player_android_options
Open

[video_player] Add opt-in Android renderer options to mitigate MediaCodec initialization failures#11338
maeddin wants to merge 2 commits intoflutter:mainfrom
maeddin:video_player_android_options

Conversation

@maeddin
Copy link

@maeddin maeddin commented Mar 24, 2026

Description

This adds Android-only player creation options to video_player so apps can configure Media3 renderer behavior per player instance.

This is intended to mitigate MediaCodec and decoder initialization failures on some Android devices, especially in scenarios where multiple video players are created, as reported in flutter/flutter#25558.

The new API introduces VideoPlayerAndroidOptions, which can be passed via VideoPlayerOptions.androidOptions. These values are forwarded through VideoCreationOptions into video_player_android during player creation.

On Android, the plugin now creates a DefaultRenderersFactory for each player instance and applies:

  • setEnableDecoderFallback(enableDecoderFallback)
  • forceDisableMediaCodecAsynchronousQueueing() when disableMediaCodecAsyncQueueing is true

This gives affected apps an opt-in way to reduce decoder initialization failures without changing default behavior for existing users.

If androidOptions is not provided, behavior remains unchanged.

Non-Android platforms ignore these options.

API changes

Example usage:

VideoPlayerController.networkUrl(
  uri,
  videoPlayerOptions: VideoPlayerOptions(
    mixWithOthers: false,
    androidOptions: VideoPlayerAndroidOptions(
      enableDecoderFallback: true,
      disableMediaCodecAsyncQueueing: true,
    ),
  ),
);

Fixes flutter/flutter#25558.

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

Copy link

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

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 VideoPlayerAndroidOptions to allow per-instance configuration of Android-specific renderer settings. The new options, enableDecoderFallback and disableMediaCodecAsyncQueueing, are passed from the Dart VideoPlayerController down to the native Android implementation. On Android, these options are used to configure a DefaultRenderersFactory for the ExoPlayer instance, which can help mitigate MediaCodec initialization failures. The changes span across the video_player, video_player_platform_interface, and video_player_android packages, including updates to data models, API methods, and the addition of corresponding tests to ensure the options are correctly forwarded and applied.

…d_options

# Conflicts:
#	packages/video_player/video_player/CHANGELOG.md
#	packages/video_player/video_player/pubspec.yaml
#	packages/video_player/video_player/test/video_player_test.dart
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.

[video_player] Initialization error when initializing multiple videos

1 participant