Skip to content

video_player: calling seekTo after video completes results in video playing without updating VideoPlayerValue #77674

Closed
flutter/plugins
#3727
@gjupac

Description

@gjupac

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();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.0Found to occur in 2.0has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions