Skip to content

[video_player] Playback speed doesn't work when setting it before initialization  #73643

Closed
flutter/packages
#7657

Description

Issue

I am mainly opening this issue to track the state of this. I am planning on fixing this myself.

Description

When setting the playback speed before initializing or when seeking, the playback speed is reset on the actual video (the video player value on the Flutter side has the set speed but the underlying player does not):

VideoPlayerController(..)
  ..setPlaybackSpeed(2) // This is ignored by the underlying player on iOS.
  ..initialize();
controller.seekTo(..); // This will also reset the playback speed on iOS.

Doctor

video_player: 1.0.1
Flutter 1.22.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7891006299 (4 weeks ago) • 2020-12-10 11:54:40 -0800
Engine • revision ae90085a84
Tools • Dart 2.10.4

Activity

  1. TahaTesser commented on Jan 11, 2021

    @TahaTesser
    Contributor

    Hi @creativecreatorormaybenot

    Here I created a complete reproducible code sample with a test video and some buttons. I can reproduce the issue where playback speed doesn't work when set before initializing the video (works as expected to set it afterward). However, playback is working as expected when seeking to Duration.zero or Duration(minutes: 0), playback doesn't reset for me. Can you please try the code sample below and give me feedback on seekTo.

    I have tested on the simulator and physical XR, both running iOS 14.3

    Code Sample

    complete code sample
    import 'package:flutter/material.dart';
    import 'package:video_player/video_player.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Material App',
          theme: ThemeData.dark(),
          home: Home(),
        );
      }
    }
    
    class Home extends StatefulWidget {
      @override
      _HomeState createState() => _HomeState();
    }
    
    class _HomeState extends State<Home> {
      VideoPlayerController _controller;
      @override
      void initState() {
        super.initState();
        _controller = VideoPlayerController.network(
          'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4',
        )
          ..addListener(() {
            setState(() {});
          })
          ..setPlaybackSpeed(2.0)
          ..setLooping(true)
          ..initialize()
          ..play();
      }
    
      @override
      void dispose() {
        _controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Material App Bar'),
            actions: [
              TextButton(
                  onPressed: () => _controller.seekTo(Duration.zero),
                  child: Text('Seek - 0')),
              TextButton(
                  onPressed: () => _controller.setPlaybackSpeed(1.0),
                  child: Text('Playback - 1'))
            ],
          ),
          body: Center(
            child: _controller.value.initialized
                ? AspectRatio(
                    aspectRatio: _controller.value.aspectRatio,
                    child: VideoPlayer(_controller),
                  )
                : Container(),
          ),
          floatingActionButton: FloatingActionButton.extended(
            label: Text('Playback increase'),
            icon: Icon(Icons.speed_sharp),
            onPressed: () {
              _controller.setPlaybackSpeed(2.0);
            },
          ),
        );
      }
    }
    flutter doctor -v
    [✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en-GB)
        • Flutter version 1.22.5 at /Users/tahatesser/Code/flutter_stable
        • Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
        • Engine revision ae90085a84
        • Dart version 2.10.4
    
    [✓] 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 12.3)
        • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
        • Xcode 12.3, Build version 12C33
        • CocoaPods version 1.10.1
    
    [!] Android Studio (version 4.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    
    [✓] VS Code (version 1.52.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.18.1
    
    [✓] Connected device (2 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios • iOS 14.3
        • iPhone 12 (mobile)     • 2FC46D8B-2A58-4ABB-B3FF-76F1AEC857FF • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    
    ! Doctor found issues in 1 category.
    [✓] Flutter (Channel master, 1.26.0-2.0.pre.275, on macOS 11.1 20C69 darwin-x64, locale en-GB)
        • Flutter version 1.26.0-2.0.pre.275 at /Users/tahatesser/Code/flutter_master
        • Framework revision d9044a8a61 (2 days ago), 2021-01-09 04:04:04 -0500
        • Engine revision caf6a8191f
        • Dart version 2.12.0 (build 2.12.0-204.0.dev)
    
    [✓] 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 12.3)
        • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
        • Xcode 12.3, Build version 12C33
        • 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.52.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.18.1
    
    [✓] Connected device (4 available)
        • Taha’s iPhone (mobile) • 00008020-001059882212002E            • ios            • iOS 14.3
        • iPhone 12 (mobile)     • 2FC46D8B-2A58-4ABB-B3FF-76F1AEC857FF • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)        • macos                                • darwin-x64     • macOS 11.1 20C69 darwin-x64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 87.0.4280.141
    
    • No issues found!

    Thank you.

  2. added
    in triagePresently being triaged by the triage team
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2021
  3. creativecreatorormaybenot commented on Jan 11, 2021

    @creativecreatorormaybenot
    ContributorAuthor

    @TahaTesser Thank you so much! ❤️

    I will try to see about the seekTo. I happens for us when we skip forward 10 seconds e.g.
    Will try to post an example later 👍

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2021
  5. TahaTesser commented on Jan 11, 2021

    @TahaTesser
    Contributor

    Hi @creativecreatorormaybenot
    seekTo related #71264
    However, it also doesn't reproduce for me #71264 (comment) here
    Thank you

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2021
  7. creativecreatorormaybenot commented on Jan 11, 2021

    @creativecreatorormaybenot
    ContributorAuthor

    @TahaTesser In our code, we call:

    await controller.seekTo(await controller.position + const Duration(seconds: 10));
    await controller.play();

    Maybe play resets the playback speed 🤔

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2021
  9. creativecreatorormaybenot commented on Jan 11, 2021

    @creativecreatorormaybenot
    ContributorAuthor

    Btw, I am using iPhone 12 Pro Max iOS 14.3 Simulator for testing, however, we also see this happening on all real devices.

    And nevermind the play call. I tested this a bunch now and I can confirm that this always happens when seekTo is called (even without play). Did you use a different device for testing?

    Source

    I figured that it might be the audio source - we are using a stream over the internet as our audio source.
    That is m3u8.

  10. TahaTesser commented on Jan 12, 2021

    @TahaTesser
    Contributor

    Hi @creativecreatorormaybenot
    Thanks for the confirmation, it must stream source, I can't reproduce even with a longer video (NullSafety Video) with a .mp4 extension.
    Since #71264 address the sekTo and it also reproduced using a stream #71264 (comment) but link no longer working to reproduce it again, I will retitle this issue for an initialization bug
    Thank you

  11. changed the title [-][video_player] Playback speed is reset on iOS[/-] [+][video_player] Playback speed doesn't work when setting it before initialization [/+] on Jan 12, 2021
  12. added and removed
    in triagePresently being triaged by the triage team
    on Jan 12, 2021
  13. 10 remaining items

  14. andreasgangso commented on Jul 31, 2023

    @andreasgangso

    I had similar problems in a similar project, and fixed it with iOS 16's new defaultRate property.

    Here, add something like this:

    if (@available(iOS 16, *)) {
        _player.defaultRate = speed
    }
    _player.rate = speed

    I'm not using video_player myself but someone should probably try this and make a PR :)

  15. github-actions commented on Jan 29, 2025

    @github-actions

    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.

  16. locked as resolved and limited conversation to collaborators on Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions