-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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
- Create new flutter app
- Paste code sample
- Run app on Android
- Video is playing now,
- Put the app in the background
- Open app from the background
- 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!