Skip to content

[video_player] Pending seek updates controller after disposal #193147

Closed
flutter/packages
#12971

Description

@Neelansh-ns

What package does this bug report belong to?

video_player

What target platforms are you seeing this bug on?

macOS. The deterministic reproduction below uses the Dart controller and a fake platform, so it does not depend on native video decoding.

Have you already upgraded your packages?

Yes. Reproduced against the latest published video_player 2.14.0 and current flutter/packages main (364fc7d23873930db22a0ba9b28da9c29c69eab5).

Dependency versions

video_player: 2.14.0 (unmodified released production source)
video_player_platform_interface: 6.9.0
video_player_android: 2.12.2
video_player_avfoundation: 2.12.0
video_player_web: 2.4.0
Flutter: 3.44.9 stable
Dart: 3.12.2

Steps to reproduce

  1. Initialize a VideoPlayerController.
  2. Start a seek, leaving the platform's returned future pending.
  3. Await controller.dispose() before the platform seek completes.
  4. Complete the platform seek future.

The same sequence occurs without a caller-initiated seek: the VideoEventType.completed handler runs pause().then((_) => seekTo(value.duration)). Disposal while that seek is pending produces an uncaught exception.

For a deterministic reproduction using the package's existing fake platform and two small regression tests:

git clone --depth 1 --single-branch --branch codex/video-player-dispose-seek-2.14.0 https://github.com/Neelansh-ns/packages.git video-player-repro
cd video-player-repro
git fetch --depth 1 https://github.com/flutter/packages.git refs/tags/video_player-v2.14.0:refs/tags/video_player-v2.14.0
git show video_player-v2.14.0:packages/video_player/video_player/lib/video_player.dart > packages/video_player/video_player/lib/video_player.dart
git show video_player-v2.14.0:packages/video_player/video_player/pubspec.yaml > packages/video_player/video_player/pubspec.yaml
cd packages/video_player/video_player
flutter pub get
flutter test --no-pub test/video_player_test.dart --plain-name 'ignores a pending' --reporter expanded

Both tests fail on the unmodified 2.14.0 controller. The same tests pass with a disposal check at the position-update boundary.

Expected results

An already-started seek may finish after disposal without writing the disposed notifier or throwing an uncaught exception. The disposed controller's value stays unchanged.

Actual results

seekTo checks disposal before awaiting the platform request, but its continuation calls _updatePosition without checking whether disposal occurred during the await. Updating the ValueNotifier then throws A VideoPlayerController was used after being disposed.

Code sample

Complete reproduction tests and fake platform.

The explicit-seek test is:

test('ignores a pending seek result after disposal', () async {
  final controller = VideoPlayerController.networkUrl(_localhostUri);
  addTearDown(controller.dispose);
  await controller.initialize();

  final seekCompleter = Completer<void>();
  fakeVideoPlayerPlatform.seekCompleter = seekCompleter;
  final VideoPlayerValue valueBeforeSeek = controller.value;
  final Future<void> pendingSeek = controller.seekTo(const Duration(milliseconds: 500));

  await controller.dispose();
  seekCompleter.complete();
  await pendingSeek;

  expect(controller.value, valueBeforeSeek);
});

Screenshots or Videos

Not applicable; this is an asynchronous exception.

Logs

A VideoPlayerController was used after being disposed.
Once you have called dispose() on a VideoPlayerController, it can no longer be used.
package:flutter/src/foundation/change_notifier.dart 184:9   ChangeNotifier.debugAssertNotDisposed.<fn>
package:flutter/src/foundation/change_notifier.dart 191:6   ChangeNotifier.debugAssertNotDisposed
package:flutter/src/foundation/change_notifier.dart 414:27  ChangeNotifier.notifyListeners
package:flutter/src/foundation/change_notifier.dart 563:5   ValueNotifier.value=
package:video_player/video_player.dart 987:5                VideoPlayerController._updatePosition
package:video_player/video_player.dart 852:5                VideoPlayerController.seekTo

Flutter Doctor output

Local paths and personal device name are redacted.

flutter doctor -v
[✓] Flutter (Channel stable, 3.44.9, on macOS 26.6.1 25G76 darwin-arm64, locale en-IN) [1,725ms]
    • Flutter version 3.44.9 on channel stable at /Users/developer/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6b182d2c75 (7 weeks ago), 2026-08-05 10:04:07 -0700
    • Engine revision 5a2a6a42cc
    • Dart version 3.12.2
    • DevTools version 2.57.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [4.0s]
    • Android SDK at /Users/developer/Library/Android/sdk
    • Emulator version 36.4.10.0 (build_id 15004761) (CL:N/A)
    • Platform android-36, build-tools 36.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.9+-14787801-b1163.94)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 27.0) [3.1s]
    • Xcode at /Users/developer/Downloads/Xcode-beta.app/Contents/Developer
    • Build 27A5252f
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [10ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (2 available) [12.3s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 26.6.1 25G76 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 153.0.8010.53
    ! Error: Browsing on the local area network for a personal iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [481ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Sep 22, 2026
  2. mbcorona commented on Sep 22, 2026

    @mbcorona
    Member

    Thanks for reporting and linking a PR.
    Routing to team-ecosystem for evaluation

  3. Neelansh-ns commented on Sep 29, 2026

    @Neelansh-ns
    Author

    @mbcorona please get the PR reviewed.

  4. added
    P2Important issues not at the top of the work list
    packageflutter/packages repository. See also p: labels.
    and removed
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    P2Important issues not at the top of the work list
    on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions