Skip to content

[video_player] [android] Width from VideoPlayerValue.size is wrong #94234

Closed
flutter/packages
#12360

Description

@codenoobforreal

Steps to Reproduce

  1. flutter create bug
  2. add the video_player plugin
  3. Run the code sample

Expected results:
the same size on iOS and android

Actual results:
height is correct but width is wrong

iOS

flutter: ======== Size(782.8, 1080.0)

android

[+1825 ms] I/flutter ( 5846): ======== Size(1696.0, 1080.0)
Code sample
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const PlayAnimation(),
    );
  }
}

class PlayAnimation extends StatefulWidget {
  const PlayAnimation({Key? key}) : super(key: key);

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

class _PlayAnimationState extends State<PlayAnimation> {
  late VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();

    _controller = VideoPlayerController.network(
      'https://user-images.githubusercontent.com/18373253/144225439-90bb67fe-69f0-43c8-bad6-cfd066844eb6.mp4',

      /// real size: 782 x 1080
    );
    _controller.setLooping(true);
    _controller.initialize().then((_) {
      debugPrint("======== ${_controller.value.size}");

      ///  output: ======== Size(1696.0, 1080.0)
      setState(() {
        _controller.play();
      });
    });
  }

  _getVideoBackground() {
    return _controller.value.isInitialized
        ? AspectRatio(
            aspectRatio: 391 / 540,
            child: VideoPlayer(_controller),
          )
        : Container();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: _getVideoBackground(),
    );
  }

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

image

Activity

  1. danagbemava-nc commented on Dec 1, 2021

    @danagbemava-nc
    Member

    Hi @codenoobforreal, thanks for filing the issue.

    Please provide a sample video for reproduction. Also, please specify which version of video_player you're using.

    Thank you

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 1, 2021
  3. codenoobforreal commented on Dec 1, 2021

    @codenoobforreal
    Author

    hi @danagbemava-nc,nice to hear that.I am using video_player: ^2.2.5.
    video below.

    loading-animation.mp4
  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 1, 2021
  5. danagbemava-nc commented on Dec 1, 2021

    @danagbemava-nc
    Member

    Hi @codenoobforreal , one more question, is this issue on android or iOS?

    Please provide the output of flutter run -v as well.

    The output is likely to be huge, so please put it into a .txt file and attach it here.

    Thank you

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

    @codenoobforreal
    Author

    android device: MI 8 SE
    log.txt

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 1, 2021
  9. maheshj01 commented on Dec 2, 2021

    @maheshj01
    Member

    Probably related to #51250

  10. danagbemava-nc commented on Dec 2, 2021

    @danagbemava-nc
    Member

    I did a bit digging into the video_player source and I noticed the size is created at this point

    size initialization in plugin

    https://github.com/flutter/plugins/blob/702fada379f3b7b70a0b3af9879aa0629a1533b6/packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart#L108

     return VideoEvent(
                eventType: VideoEventType.initialized,
                duration: Duration(milliseconds: map['duration']),
                size: Size(map['width']?.toDouble() ?? 0.0,
                    map['height']?.toDouble() ?? 0.0),
              );

    and these values are from exoplayer on the native side

    width and height from native side

    https://github.com/flutter/plugins/blob/702fada379f3b7b70a0b3af9879aa0629a1533b6/packages/video_player/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java#L274

    if (exoPlayer.getVideoFormat() != null) {
            Format videoFormat = exoPlayer.getVideoFormat();
            int width = videoFormat.width;
            int height = videoFormat.height;
            int rotationDegrees = videoFormat.rotationDegrees;
            // Switch the width/height if video was taken in portrait mode
            if (rotationDegrees == 90 || rotationDegrees == 270) {
              width = exoPlayer.getVideoFormat().height;
              height = exoPlayer.getVideoFormat().width;
            }
            event.put("width", width);
            event.put("height", height);
          }

    If you look at the logs, you'll notice this somewhere in there

    codec information
    [        ] D/CCodec  ( 5846): } and output: AMessage(what = 0x00000000) = {
    [        ] D/CCodec  ( 5846):   int32_t android._color-format = 2135033992
    [        ] D/CCodec  ( 5846):   int32_t android._video-scaling = 1
    [        ] D/CCodec  ( 5846):   Rect crop(0, 0, 1695, 1079)
    [        ] D/CCodec  ( 5846):   int32_t color-standard = 1
    [        ] D/CCodec  ( 5846):   int32_t color-range = 2
    [        ] D/CCodec  ( 5846):   int32_t color-transfer = 3
    [        ] D/CCodec  ( 5846):   int32_t height = 1080
    [        ] D/CCodec  ( 5846):   int32_t max-height = 1080
    [        ] D/CCodec  ( 5846):   int32_t max-width = 1696
    [        ] D/CCodec  ( 5846):   string mime = "video/raw"
    [        ] D/CCodec  ( 5846):   int32_t rotation-degrees = 0
    [        ] D/CCodec  ( 5846):   int32_t sar-height = 1
    [        ] D/CCodec  ( 5846):   int32_t sar-width = 1
    [        ] D/CCodec  ( 5846):   int32_t width = 1696
    [        ] D/CCodec  ( 5846):   int32_t android._dataspace = 260
    [        ] D/CCodec  ( 5846):   int32_t color-format = 2130708361
    [        ] D/CCodec  ( 5846): }

    which is coming from exoplayer, you'll notice that the width is reported as 1696 which matches what you got. So I decided to look into it further to see if anyone had reported this to exoplayer and I found this GH thread google/ExoPlayer#3690, so I decided to try what was stated in google/ExoPlayer#3690 (comment) with a native android application.

    D/test: height: 1080
    D/test: width: 1696
    D/test: pixelWidthHeightRatio: 0.46153846
        width * pixelWidthHeightRatio: 782.7692

    The value is closer to what expected it to be. It looks like the pixelWidthHeightRatio is not being taken into account when retrieving the width and height. I don't know why that is the case, labelling for further insight.

    code samples

    native sample

    ExoTest.zip

    flutter sample

    import 'package:flutter/material.dart';
    import 'package:video_player/video_player.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            // This is the theme of your application.
            //
            // Try running your application with "flutter run". You'll see the
            // application has a blue toolbar. Then, without quitting the app, try
            // changing the primarySwatch below to Colors.green and then invoke
            // "hot reload" (press "r" in the console where you ran "flutter run",
            // or simply save your changes to "hot reload" in a Flutter IDE).
            // Notice that the counter didn't reset back to zero; the application
            // is not restarted.
            primarySwatch: Colors.blue,
          ),
          home: const PlayAnimation(),
        );
      }
    }
    
    class PlayAnimation extends StatefulWidget {
      const PlayAnimation({Key? key}) : super(key: key);
    
      @override
      _PlayAnimationState createState() => _PlayAnimationState();
    }
    
    class _PlayAnimationState extends State<PlayAnimation> {
      late VideoPlayerController _controller;
    
      @override
      void initState() {
        super.initState();
    
        _controller = VideoPlayerController.network(
          'https://user-images.githubusercontent.com/18373253/144225439-90bb67fe-69f0-43c8-bad6-cfd066844eb6.mp4',
    
          /// real size: 782 x 1080
        );
        _controller.setLooping(true);
        _controller.initialize().then((_) {
          debugPrint("======== ${_controller.value.size}");
    
          ///  output: ======== Size(1696.0, 1080.0)
          setState(() {
            _controller.play();
          });
        });
      }
    
      _getVideoBackground() {
        return _controller.value.isInitialized
            ? AspectRatio(
                aspectRatio: 391 / 540,
                child: VideoPlayer(_controller),
              )
            : Container();
      }
    
      @override
      Widget build(BuildContext context) {
        return Center(
          child: _getVideoBackground(),
        );
      }
    
      @override
      void dispose() {
        super.dispose();
        _controller.dispose();
      }
    }
    
    logs

    run_log_android.txt

    run_log_ios.txt

    flutter doctor -v
    [✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale en-GB)
        • Flutter version 2.5.3 at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 18116933e7 (7 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/nexus/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • 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.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • 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.10+0-b96-7249189)
    
    [☠] IntelliJ IDEA Community Edition (the doctor check crashed)
        ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
        ✗ FormatException: Unexpected extension byte (at offset 5)
        • #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1788:7)
          #1      Utf8Decoder.convert (dart:convert/utf.dart:318:42)
          #2      InputStream.readString (package:archive/src/util/input_stream.dart:199:30)
          #3      new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
          #4      ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
          #5      ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
          #6      IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
          #7      IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
          #8      IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
          #9      IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
          #10     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
          #11     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:109:18)
          #12     _rootRun (dart:async/zone.dart:1428:13)
          #13     _CustomZone.run (dart:async/zone.dart:1328:19)
          #14     _runZoned (dart:async/zone.dart:1863:10)
          #15     runZonedGuarded (dart:async/zone.dart:1851:12)
          #16     runZoned (dart:async/zone.dart:1782:12)
          #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
          #18     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:200:9)
          #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:304:47)
          #20     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:50:47)
          #21     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1274:12)
          <asynchronous suspension>
          #22     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1125:27)
          <asynchronous suspension>
          #23     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
          <asynchronous suspension>
          #25     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:288:9)
          <asynchronous suspension>
          #26     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #27     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:236:5)
          <asynchronous suspension>
          #28     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
          <asynchronous suspension>
          #29     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #30     main (package:flutter_tools/executable.dart:92:3)
          <asynchronous suspension>
    
    
    [✓] VS Code (version 1.62.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (4 available)
        • sdk gphone arm64 (mobile) • emulator-5554                        • android-arm64  • Android 11 (API 30) (emulator)
        • iPhone 13 (mobile)        • 7515F01A-C1B6-456E-8559-8D2383D3719D • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)           • macos                                • darwin-arm64   • macOS 11.6 20G165 darwin-arm
        • Chrome (web)              • chrome                               • web-javascript • Google Chrome 96.0.4664.55
    
    ! Doctor found issues in 1 category.
    [✓] Flutter (Channel master, 2.6.0-12.0.pre.883, on macOS 11.6 20G165 darwin-arm, locale en-GB)
        • Flutter version 2.6.0-12.0.pre.883 at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 049ea73c4d (3 hours ago), 2021-12-01 20:19:02 -0800
        • Engine revision c2fcadef89
        • Dart version 2.16.0 (build 2.16.0-56.0.dev)
        • DevTools version 2.8.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • 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.10+0-b96-7249189)
    
    [☠] IntelliJ IDEA Community Edition (the doctor check crashed)
        ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
        ✗ FormatException: Unexpected extension byte (at offset 5)
        • #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
          #1      Utf8Decoder.convert (dart:convert/utf.dart:351:42)
          #2      InputStream.readString (package:archive/src/util/input_stream.dart:207:30)
          #3      new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
          #4      ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
          #5      ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
          #6      IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
          #7      IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
          #8      IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
          #9      IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
          #10     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
          #11     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:109:18)
          #12     _rootRun (dart:async/zone.dart:1426:13)
          #13     _CustomZone.run (dart:async/zone.dart:1328:19)
          #14     _runZoned (dart:async/zone.dart:1861:10)
          #15     runZonedGuarded (dart:async/zone.dart:1849:12)
          #16     runZoned (dart:async/zone.dart:1780:12)
          #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
          #18     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:198:9)
          #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:302:47)
          #20     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:50:48)
          #21     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1320:12)
          <asynchronous suspension>
          #22     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
          <asynchronous suspension>
          #23     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
          <asynchronous suspension>
          #25     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
          <asynchronous suspension>
          #26     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #27     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
          <asynchronous suspension>
          #28     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
          <asynchronous suspension>
          #29     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #30     main (package:flutter_tools/executable.dart:94:3)
          <asynchronous suspension>
    
    
    [✓] VS Code (version 1.62.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (4 available)
        • sdk gphone arm64 (mobile) • emulator-5554                        • android-arm64  • Android 11 (API 30) (emulator)
        • iPhone 13 (mobile)        • 7515F01A-C1B6-456E-8559-8D2383D3719D • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)           • macos                                • darwin-arm64   • macOS 11.6 20G165 darwin-arm
        • Chrome (web)              • chrome                               • web-javascript • Google Chrome 96.0.4664.55
    
    ! Doctor found issues in 1 category.
  11. added
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Dec 2, 2021
  12. 13 remaining items

  13. tangTdc123 commented on Dec 7, 2023

    @tangTdc123
  14. TimYusR commented on May 8, 2025

    @TimYusR

    Seems like its not a duplicate.

    I have 2 videos.
    First is horizontal, captured by iPhone, has MOV format. The videoController.value returns Size(1280, 720) for it.
    Second is vertical, captured by Android Emulator API 35, has MP4 format. In that case videoController.value returns Size(1280, 720), which is not correct because its vertical. And my vertical video stretches by width in video_player.

    The above appears on Android Emulator API 35.

    On my Xiaomi Redmi Note 8, Android 11, vertical videos of any format are randomly rotated.

    First horizontal video screen

    Image

    Secoind vertical video screen

    Image

    Videos rotated screens

    Image

    Image

  15. github-actions commented on Sep 16, 2026

    @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 Sep 16, 2026
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 listfound in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6has 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-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions