Skip to content

[video_player][iOS] VideoPlayerController.value.position not updating on video completion for video_player_avfoundation > 2.4.2  #124475

@neeraj-dhake

Description

@neeraj-dhake

Steps to Reproduce

  1. Execute flutter run on the code sample linked below.
  2. Wait till the end of the video (17s) and some more.
  3. This doesn't happen if I pin the video_player_avfoundation to 2.4.1

Expected results: The text below the video should get updated to Completed

Actual results: The text below the video doesn't get updated to Completed and remains isPlaying

From my debugging, what I could see was that the following code was triggered:

        case VideoEventType.completed:
          // In this case we need to stop _timer, set isPlaying=false, and
          // position=value.duration. Instead of setting the values directly,
          // we use pause() and seekTo() to ensure the platform stops playing
          // and seeks to the last frame of the video.
          pause().then((void pauseResult) => seekTo(value.duration));
          break;

but in the seekTo function, the following does not complete:

    await _videoPlayerPlatform.seekTo(_textureId, position);

The change in video_player_avfoundation = 2.4.2 was to make the seek async, so its highly likely that this is the issue.

Code sample `main.dart`:
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Video Player')),
        body: const VideoPlayerExample(),
      ),
    );
  }
}

class VideoPlayerExample extends StatefulWidget {
  const VideoPlayerExample({super.key});

  @override
  VideoPlayerExampleState createState() => VideoPlayerExampleState();
}

class VideoPlayerExampleState extends State<VideoPlayerExample> {
  final controller = VideoPlayerController.network(
    'https://cdnapisec.kaltura.com/p/309/sp/0/playManifest/entryId/1_rcit0qgs/format/applehttp/protocol/https/flavorParamId/301971/manifest.m3u8',
  );
  late Future<void> initializeVideoPlayerFuture;

  @override
  void initState() {
    initializeVideoPlayerFuture = controller.initialize();
    controller.play();
    controller.addListener(listener);
    super.initState();
  }

  @override
  void dispose() {
    controller.removeListener(listener);
    controller.dispose();
    super.dispose();
  }

  void listener() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        FutureBuilder(
          future: initializeVideoPlayerFuture,
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.done) {
              return AspectRatio(
                aspectRatio: controller.value.aspectRatio,
                child: VideoPlayer(controller),
              );
            } else {
              return const CircularProgressIndicator();
            }
          },
        ),
        const SizedBox(height: 20),
        Text(
          controller.value.position >= controller.value.duration
              ? 'Completed'
              : 'Playing',
          style: const TextStyle(fontSize: 24),
        ),
      ],
    );
  }
}

pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  video_player: ^2.6.1
  video_player_avfoundation: ^2.4.2 # change this to 2.4.1 to see that this doesn't happen.
Logs

Run flutter analyze and attach any output of that command below.

Analyzing video_player_example...                                       
No issues found! (ran in 1.0s)

Finally, paste the output of running flutter doctor -v here.

[✓] Flutter (Channel stable, 3.7.10, on macOS 13.3 22E252 darwin-arm64, locale en-IN)
    • Flutter version 3.7.10 on channel stable at /Users/neerajdhake/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4b12645012 (5 days ago), 2023-04-03 17:46:48 -0700
    • Engine revision ec975089ac
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/neerajdhake/android
    • Platform android-33, build-tools 32.0.0
    • ANDROID_HOME = /Users/neerajdhake/android
    • Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.0.4.1.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2022.2.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.77.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.62.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.3 22E252 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 112.0.5615.49

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: regressionIt was better in the past than it is nowfound in release: 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions