Skip to content

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

Closed
gjupac opened this issue Mar 9, 2021 · 5 comments · Fixed by flutter/plugins#3727
Labels
found in release: 2.0 Found to occur in 2.0 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels.

Comments

@gjupac
Copy link

gjupac commented Mar 9, 2021

Steps to reproduce:

  1. Let a video finish playing
  2. call VideoPlayerController.seekTo() to some time < the video's duration

Expected result:
Video seeks to correct time and A) remains paused OR B) starts playing and sends periodic VideoPlayerValue updates

Actual 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 and VideoPlayerController.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)
import '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> {
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        'https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.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();
  }
}
@TahaTesser TahaTesser added the in triage Presently being triaged by the triage team label Mar 9, 2021
@TahaTesser
Copy link
Member

Hi @gjupac
Thanks for filing the issue, I can reproduce it using video_player: ^2.0.0

Preview

ezgif com-gif-maker

code sample
import '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

@TahaTesser TahaTesser added found in release: 2.0 Found to occur in 2.0 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: first party p: video_player The Video Player plugin and removed in triage Presently being triaged by the triage team labels Mar 9, 2021
@cyanglaz cyanglaz added the P2 Important issues not at the top of the work list label Mar 11, 2021
@KyleFin
Copy link
Contributor

KyleFin commented Mar 12, 2021

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?

fllutterWebVideoPlayer

flutter doctor -v

    [✓] Flutter (Channel master, 2.1.0-11.0.pre.165, on Linux, locale en_US.UTF-8)
        • Flutter version 2.1.0-11.0.pre.165 at /home/kfin/flutter
        • Framework revision 698d438960 (4 days ago), 2021-03-09 07:53:21 +0100
        • Engine revision 2441c476a6
        • Dart version 2.13.0 (build 2.13.0-116.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /home/kfin/Android/Sdk
        • Platform android-30, build-tools 30.0.3
        • Java binary at: /opt/android-studio/jre/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Android Studio (version 4.1)
        • Android Studio at /opt/android-studio
        • Flutter plugin version 54.0.1
        • Dart plugin version 201.9335
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [✓] Connected device (1 available)
        • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88
    
    • No issues found

@gjupac
Copy link
Author

gjupac commented Mar 12, 2021

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).

@KyleFin
Copy link
Contributor

KyleFin commented Mar 16, 2021

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).
On web, the behavior seems correct: when clicking play on a completed video, the time resets to 0 and the video begins playing from the beginning.

I also observe the incorrect behavior on iOS simulator with video_player version ^1.0.0

@github-actions
Copy link

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 flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
found in release: 2.0 Found to occur in 2.0 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants