flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.18k stars 26.64k forks source link

video_player: VideoPlayerController.value.size.height should be an int #147475

Closed stephane-archer closed 2 weeks ago

stephane-archer commented 2 weeks ago

Use case

VideoPlayerController controller = VideoPlayerController.file(myFile);
await controller.initialize();
print(controller.value.size.height);
print(controller.value.size.width);

height and width are double, are you aware of any floating point number resolution? I think int would be more appropriate.

Proposal

move to the right type

darshankawar commented 2 weeks ago

@stephane-archer Both, height and width are implemented as double:

Screenshot 2024-04-29 at 4 02 38 PM

These properties are then being used in AspectRatio as below:

Screenshot 2024-04-29 at 4 02 59 PM

Probably returning double is more safe than returning these property values as int.

stephane-archer commented 2 weeks ago

@darshankawar width and height are video resolution. the typical values would be 1920 and 1080 respectively. I don't think videos with 0,5 pixels exist. The associated AspectRatio would be 16:9. here it makes sense to use a double for this value but it's not because to calculate an AspectRatio you need a floating point division that width and height should be defined as double

darshankawar commented 2 weeks ago

Thanks for the feedback.

stuartmorgan commented 2 weeks ago

height and width are double, are you aware of any floating point number resolution?

AVPlayer returns video sizes using doubles (CGSize), so using an int would potentially destroy information from the platform level. Given that, plus the fact that altering the type now would be a breaking change, we will be keeping double as the type. Clients can always round if they are not concerned about potential loss of precision if there are cases where AVPlayer returns non-integer values.

stephane-archer commented 2 weeks ago

@stuartmorgan Do you have any idea why AVPlayer would return video sizes using doubles? Do I miss something?