-
Notifications
You must be signed in to change notification settings - Fork 28.6k
video_player: calling seekTo after video completes results in video playing without updating VideoPlayerValue #77674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @gjupac Previewcode sampleimport 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(VideoApp());
class VideoApp extends StatefulWidget {
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'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(() {});
})
..addListener(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller.value.isInitialized
? Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
),
Text(
'${_controller.value.position}/${_controller.value.duration}'),
],
)
: Container(),
),
floatingActionButton: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
FloatingActionButton(
onPressed: () {
setState(() {
_controller.seekTo(
_controller.value.position - Duration(seconds: 5));
});
},
child: Icon(
Icons.fast_rewind,
),
),
FloatingActionButton(
onPressed: () {
setState(() {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
FloatingActionButton(
onPressed: () {
setState(() {
_controller.seekTo(_controller.value.duration);
});
},
child: Icon(
Icons.skip_next,
),
),
],
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
} flutter doctor -v[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.2 20D80 darwin-x64, locale en-GB)
• Flutter version 2.0.1 at /Users/tahatesser/Code/flutter_stable
• Framework revision c5a4b4029c (5 days ago), 2021-03-04 09:47:48 -0800
• Engine revision 40441def69
• Dart version 2.12.0
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Volumes/Extreme/SDK
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Volumes/Extreme/SDK
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.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 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.54.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.20.0
[✓] Connected device (4 available)
• IN2011 (mobile) • c9d8ee0c • android-arm64 • Android 11 (API 30)
• Taha’s iPad (mobile) • 00008020-000255113EE8402E • ios • iOS 14.4
• macOS (desktop) • macos • darwin-x64 • macOS 11.2.2 20D80 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.82
• No issues found! Thank you |
I was unable to reproduce on web (see video of back button correctly resetting video to beginning and not playing). I don't currently have access to an iOS device. Is this specific to Android? flutter doctor -v
|
Technically I haven't tried running my demo code on an iOS device but I was able to reproduce the same issue within the app I'm working on on an iOS device (iPhoneXR 14.4). |
I confirmed the incorrect behavior happens on my iOS simulator. Another observation on iOS (and presumably Android): after the video finishes, if I click play the timer continues beyond the video duration (image stays on the last frame). I also observe the incorrect behavior on iOS simulator with video_player version ^1.0.0 |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce:
VideoPlayerController.seekTo()
to some time < the video's durationExpected result:
Video seeks to correct time and A) remains paused OR B) starts playing and sends periodic
VideoPlayerValue
updatesActual result:
Video seeks to correct time and is seemingly paused BUT the video continues to play (once it buffers) while
VideoPlayerController.value.position
does not change andVideoPlayerController.value.isPlaying
stays false.Device used:
Pixel 3 XL Android 11
Code demo used to reproduce (modified example from README with fast forward/rewind buttons + live play time)
The text was updated successfully, but these errors were encountered: