flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.2k stars 27.49k forks source link

[video_player] Video restarts on scrubbing the progress indicator to the end #92658

Closed Claudiatp22 closed 3 years ago

Claudiatp22 commented 3 years ago

Use case

After the merge of this PR our application started experiencing some unexpected behaviours when the user dragged the video player position until the end, specifically this new condition in the play() method. This was an unexpected change that wasn't reflected in the changelog 😕.

Proposal

Since this behaviour is not exposed in any way we made a workaround on our code to avoid the video restarting by itself. However, since this is more like a feature would it be possible to make it optional?

maheshj01 commented 3 years ago

Hi @Claudiatp22, thanks for filing the issue, I can confirm the video restarts on scrubbing the progress bar to the end as of video_player: 2.2.6 on all video_player supported platforms (iOS, Android, web)

code sample ```dart import 'dart:async'; import 'package:flutter/material.dart'; import 'package:video_player/video_player.dart'; Future main() async { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp(home: VideoApp()); } } class VideoApp extends StatefulWidget { @override _VideoAppState createState() => _VideoAppState(); } class _VideoAppState extends State { late VideoPlayerController _controller; @override void initState() { super.initState(); _controller = VideoPlayerController.network( 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4') ..initialize().then((_) { // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed. setState(() {}); }); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Video Demo', home: Scaffold( body: Container( alignment: Alignment.center, padding: EdgeInsets.symmetric(horizontal: 8), child: _controller.value.isInitialized ? AspectRatio( aspectRatio: _controller.value.aspectRatio, child: Stack( alignment: Alignment.bottomCenter, children: [ VideoPlayer(_controller), VideoProgressIndicator(_controller, allowScrubbing: true), ], ), ) : Container(), ), floatingActionButton: FloatingActionButton( onPressed: () { setState(() { _controller.value.isPlaying ? _controller.pause() : _controller.play(); }); }, child: Icon( _controller.value.isPlaying ? Icons.pause : Icons.play_arrow, ), ), ), ); } @override void dispose() { super.dispose(); _controller.dispose(); } } ```
stuartmorgan commented 3 years ago

to avoid the video restarting by itself

To make sure I'm understanding correctly: is the behavior that if the video is playing, and is scrubbed to the end, it automatically jumps to the beginning and continues playing?

If so, that's just a bug; the intent of the change was to change the behavior of explicitly starting playback when the video is at the end.

maheshj01 commented 3 years ago

To make sure I'm understanding correctly: is the behavior that if the video is playing, and is scrubbed to the end, it automatically jumps to the beginning and continues playing?

Yes, if the video is manually scrubbed to the end it jumps to the beginning.

If so, that's just a bug

Labeling this issue as a bug instead of proposal

flutter doctor -v ``` [✓] Flutter (Channel master, 2.6.0-12.0.pre.478, on macOS 12.0.1 21A559 darwin-arm, locale en-GB) • Flutter version 2.6.0-12.0.pre.478 at /Users/mahesh/Documents/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision abecef6ed3 (5 days ago), 2021-10-26 20:31:29 -0700 • Engine revision 925bae45ee • Dart version 2.15.0 (build 2.15.0-250.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.0) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.2) • 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 11.0.8+10-b944.6916264) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 60.1.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.59.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.27.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 12.0.1 21A559 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.54 • No issues found! ``` ``` [✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale en-GB) • Flutter version 2.5.3 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 18116933e7 (2 weeks ago), 2021-10-15 10:46:35 -0700 • Engine revision d3ea636dc5 • Dart version 2.14.4 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 13.0, Build version 13A233 • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.2) • 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 11.0.8+10-b944.6916264) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 60.1.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.59.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.27.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 12.0.1 21A559 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.54 • No issues found! ```
newtaDev commented 3 years ago

@stuartmorgan I'm also facing a similar issue but only on flutter web in android works fine

but this issue occurs only for the first time, after hot restart/reload works fine

Sample video -

https://user-images.githubusercontent.com/85326522/140480457-ab21345a-76e2-4b0e-b4ec-027c89f0e712.mp4

newtaDev commented 3 years ago

92658 This issue still exists,

ISSUE 1

  • when i try to play video from assets in flutter web

  • NOTE - this issue occurs only for the first time, after hot restart/reload works fine

ISSUE 2

To reproduce issue 2

import 'dart:async';

import 'package:flutter/material.dart';

import 'package:video_player/video_player.dart';

Future<void> main() async {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: VideoApp());
  }
}

class VideoApp extends StatefulWidget {
  @override
  _VideoAppState createState() => _VideoAppState();
}

class _VideoAppState extends State<VideoApp> {
  late VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.asset(
        'https://samplelib.com/lib/preview/mp4/sample-10s.mp4')
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Video Demo',
      home: Scaffold(
        body: Container(
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: 8),
          child: _controller.value.isInitialized
              ? AspectRatio(
                  aspectRatio: _controller.value.aspectRatio,
                  child: Stack(
                    alignment: Alignment.bottomCenter,
                    children: [
                      VideoPlayer(_controller),
                      VideoProgressIndicator(_controller, allowScrubbing: true),
                    ],
                  ),
                )
              : Container(),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              _controller.value.isPlaying
                  ? _controller.pause()
                  : _controller.play();
            });
          },
          child: Icon(
            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
          ),
        ),
      ),
    );
  }

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

flutter doctor -v

[✓] Flutter (Channel stable, 2.5.3, on Ubuntu 20.04.3 LTS
    5.11.0-38-generic, locale en_GB.UTF-8)
    • Flutter version 2.5.3 at /home/dev/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (4 weeks ago), 2021-10-15
      10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK
    version 30.0.2)
    • Android SDK at /home/dev/Android/Sdk
    • Platform android-31, build-tools 30.0.2
    • ANDROID_HOME = /home/dev/Android/Sdk
    • Java binary at:
      /home/dev/Downloads/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

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 4.1)
    • Android Studio at /home/dev/Downloads/android-studio
    • Flutter plugin version 52.0.1
    • Dart plugin version 201.9245
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.61.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.28.0

[✓] Connected device (3 available)
    • Redmi 6 Pro (mobile) • 48b191740505 • android-arm64  •
      Android 9 (API 28)
    • Linux (desktop)      • linux        • linux-x64      •
      Ubuntu 20.04.3 LTS 5.11.0-38-generic
    • Chrome (web)         • chrome       • web-javascript •
      Google Chrome 95.0.4638.69

• No issues found!
stuartmorgan commented 3 years ago

@newtaDev The video you posted is not showing this issue. You should file a new issue for your bug.

newtaDev commented 3 years ago

@stuartmorgan

Okey. Thanks for responding

I have opened new issue #93486 please check.

github-actions[bot] commented 2 years ago

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.