Skip to content

Exception on the video player after the app opens from the background  #154602

Closed
flutter/packages
#7722

Description

@ziperjohn

What package does this bug report belong to?

video_player

What target platforms are you seeing this bug on?

Android

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
[Paste file content here]

Steps to reproduce

  1. Create new flutter app
  2. Paste code sample
  3. Run app on Android
  4. Video is playing now,
  5. Put the app in the background
  6. Open app from the background
  7. An exception occurs

Expected results

The video will start playing again without exception.

I tested this situation on iOS and work fine.

Actual results

After open app from the background an exception occurs.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Future already completed
E/flutter (17608): #0 _AsyncCompleter.complete (dart:async/future_impl.dart:43:31)
E/flutter (17608): #1 VideoPlayerController.initialize.eventListener (package:video_player/video_player.dart:468:33)
E/flutter (17608): #2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (17608): #3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
E/flutter (17608): #4 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
E/flutter (17608): #5 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (17608): #6 _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
E/flutter (17608): #7 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (17608): #8 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter (17608): #9 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
E/flutter (17608): #10 _DelayedData.perform (dart:async/stream_impl.dart:541:14)
E/flutter (17608): #11 _PendingEvents.handleNext (dart:async/stream_impl.dart:646:11)
E/flutter (17608): #12 _PendingEvents.schedule. (dart:async/stream_impl.dart:617:7)
E/flutter (17608): #13 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (17608): #14 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: VideoPlayerScreen(),
    );
  }
}

class VideoPlayerScreen extends StatefulWidget {
  const VideoPlayerScreen({super.key});

  @override
  State<VideoPlayerScreen> createState() => _VideoPlayerScreenState();
}

class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
  late VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();

    _controller =
        VideoPlayerController.networkUrl(Uri.parse('https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'))
          ..initialize().then((_) {
            // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
            setState(() {});
          });

    _controller.setLooping(true);
    _controller.play();
  }

  @override
  void dispose() {
    super.dispose();

    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("video player"),
      ),
      body: Center(
        child: _controller.value.isInitialized
            ? AspectRatio(
                aspectRatio: _controller.value.aspectRatio,
                child: VideoPlayer(_controller),
              )
            : Container(),
      ),
    );
  }
}

Screenshots or Videos

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-arm64, locale en-CZ)
    • Flutter version 3.24.0 on channel stable at /Users/janvaverka/Development Tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (5 weeks ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/janvaverka/Library/Android/sdk
    • Platform android-35, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.92.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.96.0

[✓] Connected device (4 available)
    • SM A528B (mobile)               • RZCT101GZRW           • android-arm64  • Android 14 (API 34)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 128.0.6613.114
    ! Error: Browsing on the local area network for Ziper. 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)
    ! Error: Browsing on the local area network for Ziper. 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
    • All expected network resources are available.

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Sep 4, 2024
  2. huycozy commented on Sep 4, 2024

    @huycozy
    Member

    I can also see the issue on my device Pixel 7, Android 14. When bringing app back to the foreground, it only renders white background, need to wait a while for the video to render the frames.

    Demo video
    Screen.Recording.2024-09-04.at.16.19.43.mov

    Reproduced on video_player: ^2.9.1 and Flutter stable 3.24.1/master 3.25.0-1.0.pre.248.

  3. added
    c: crashStack traces logged to the console
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-androidOwned by Android platform team
    fyi-ecosystemFor the attention of Ecosystem team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 4, 2024
  4. qinjing100 commented on Sep 4, 2024

    @qinjing100

    I also encounter the problem in debug mode in Android 11, Android 14.

    1. I play the video from local file
    2. bring app to background
    3. bring app foreground again
    4. Bad state: Future already completed
    I/flutter (10951): ----------------FIREBASE CRASHLYTICS----------------
    I/flutter (10951): Bad state: Future already completed
    I/flutter (10951): #0      _AsyncCompleter.complete (dart:async/future_impl.dart:43:31)
    I/flutter (10951): #1      VideoPlayerController.initialize.eventListener (package:video_player/video_player.dart:468:33)
    I/flutter (10951): #2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
    I/flutter (10951): #3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
    I/flutter (10951): #4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
    I/flutter (10951): #5      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
    I/flutter (10951): #6      _MapStream._handleData (dart:async/stream_pipe.dart:218:10)
    I/flutter (10951): #7      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
    I/flutter (10951): #8      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
    I/flutter (10951): #9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
    I/flutter (10951): #10     _DelayedData.perform (dart:async/stream_impl.dart:541:14)
    I/flutter (10951): #11     _PendingEvents.handleNext (dart:async/stream_impl.dart:646:11)
    I/flutter (10951): #12     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:617:7)
    I/flutter (10951): #13     _micro
    I/flutter (10951): ----------------------------------------------------
    W/FirebaseCrashlytics(10951): Unable to read App Quality Sessions session id.
    Restarted application in 3,772ms.
    
    

    Reproduced on video_player: ^2.9.1 and Flutter stable 3.24.0

    [✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-x64, locale zh-Hans-HK)
        • Flutter version 3.24.0 on channel stable at /Users/bruce/fvm/versions/3.24.0
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 80c2e84975 (5 weeks ago), 2024-07-30 23:06:49 +0700
        • Engine revision b8800d88be
        • Dart version 3.5.0
        • DevTools version 2.37.2
        • Pub download mirror https://pub.flutter-io.cn
        • Flutter download mirror https://storage.flutter-io.cn
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/bruce/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
        • All Android licenses accepted.
    
    [!] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15E204a
        ✗ Unable to get list of installed Simulator runtimes.
        ! CocoaPods 1.11.3 out of date (1.13.0 is recommended).
            CocoaPods is a package manager for iOS or macOS platform code.
            Without CocoaPods, plugins will not work on iOS or macOS.
            For more info, see https://flutter.dev/to/platform-plugins
          To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    
    [✓] VS Code (version 1.92.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.94.0
    
    [!] Proxy Configuration
        • HTTP_PROXY is set
        ! NO_PROXY is not set
    
    [✓] Connected device (3 available)
        • V2164A (mobile) • 344393009600178 • android-arm64  • Android 11 (API 30)
        • macOS (desktop) • macos           • darwin-x64     • macOS 14.6.1 23G93 darwin-x64
        • Chrome (web)    • chrome          • web-javascript • Google Chrome 128.0.6613.114
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
    
    

    this problem not occur in Android 9.

    Please help fix this issue, thanks a lot.

  5. msayed-cs commented on Sep 5, 2024

    @msayed-cs

    Same issue here

  6. reidbaker commented on Sep 5, 2024

    @reidbaker
    Contributor

    @ziperjohn @msayed-net is this bug a regression? if so what version of video player works correctly (so we can bisect)

  7. 24 remaining items

  8. lhlyu commented on Sep 29, 2024

    @lhlyu

    Tried it, no issues with 2.7.1, but it doesn’t work with 2.7.5.

  9. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 3, 2024
  10. michael-joseph-payne commented on Oct 4, 2024

    @michael-joseph-payne

    It looks like this was fixed in video_player_android 2.7.6

    video_player currently depends on video_player_android 2.3.5, so I imagine anyone with this issue would want to try the following:

    dependency_overrides:
      video_player_android: 2.7.6
    

    I'm currently testing and will feedback if I still see this.

  11. matanlurey commented on Oct 4, 2024

    @matanlurey
    Contributor

    Yes, that's why this issue is closed. Do not write "this was fixed" on a closed issue.

  12. locked as resolved and limited conversation to collaborators on Oct 4, 2024
  13. gnprice commented on Oct 4, 2024

    @gnprice
  14. unlocked this conversation on Oct 4, 2024
  15. locked as resolved and limited conversation to collaborators on Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowfound in release: 3.24Found to occur in 3.24found in release: 3.25Found to occur in 3.25has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions