Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
codenoobforreal opened this issue Nov 26, 2021 · 8 comments
Open
Labels
found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@codenoobforreal
Copy link

codenoobforreal commented Nov 26, 2021

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

@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Dec 1, 2021
@danagbemava-nc
Copy link
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

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 1, 2021
@codenoobforreal
Copy link
Author

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

loading-animation.mp4

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 1, 2021
@danagbemava-nc
Copy link
Member

danagbemava-nc commented Dec 1, 2021

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

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 1, 2021
@codenoobforreal
Copy link
Author

android device: MI 8 SE
log.txt

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 1, 2021
@maheshmnj
Copy link
Member

Probably related to #51250

@danagbemava-nc
Copy link
Member

danagbemava-nc commented Dec 2, 2021

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.

@danagbemava-nc danagbemava-nc added found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: first party p: video_player The Video Player plugin platform-android Android applications specifically and removed in triage Presently being triaged by the triage team labels Dec 2, 2021
@danagbemava-nc danagbemava-nc changed the title [video player] wrong video size [video_player] [android] wrong video size Dec 2, 2021
@danagbemava-nc danagbemava-nc changed the title [video_player] [android] wrong video size [video_player] [android] Width from VideoPlayerValue.size in wrong Dec 2, 2021
@danagbemava-nc danagbemava-nc changed the title [video_player] [android] Width from VideoPlayerValue.size in wrong [video_player] [android] Width from VideoPlayerValue.size is wrong Dec 2, 2021
@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label Dec 2, 2021
@JoinLi
Copy link

JoinLi commented Jul 1, 2022

I found that the width and height of the video are only obtained once during initialization, but this does not meet my expectations. If it is a live broadcast and the width and height of the video will change, there will be a problem with the aspect ratio at this time. I hope his width High is real time.

bluejoyq added a commit to bluejoyq/flutter_video_demo that referenced this issue Jul 5, 2022
flutter/flutter#94234 참조.
size 갱신 안되는 버그 존재해서
더이상 진행불가.
적응형 스트리밍은 이미 적용되어있음.
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
@Hixie Hixie removed the plugin label Jul 6, 2023
@tangTdc123

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests

7 participants