Fix video_control sizing calc for VideoPlayerLibAvControl.

main
Hank Grabowski 2023-04-04 12:22:12 -04:00
rodzic 6de89aef26
commit 2456ee9d38
1 zmienionych plików z 20 dodań i 21 usunięć

Wyświetl plik

@ -56,24 +56,19 @@ class _VideoPlayerLibAvControlState extends State<VideoPlayerLibAvControl> {
@override
Widget build(BuildContext context) {
final size = videoPlayerController.value.size;
final horizontalScale = size.width / widget.width;
final verticalScale = size.height / widget.height;
final scaling = min(horizontalScale, verticalScale);
final videoWidth = scaling * size.width;
final videoHeight = scaling * size.height;
if (!videoPlayerController.value.isInitialized) {
return SizedBox(
width: videoWidth,
height: videoHeight,
child: const Card(
color: Colors.black12,
shape: RoundedRectangleBorder(),
child: CircularProgressIndicator(),
),
);
late final double videoWidth;
late final double videoHeight;
if (needsToLoad) {
videoWidth = widget.width;
videoHeight = widget.height;
} else {
final horizontalScale = widget.width / size.width;
final verticalScale = widget.height / size.height;
final scaling = min(horizontalScale, verticalScale);
videoWidth = scaling * size.width;
videoHeight = scaling * size.height;
}
print('Video Width: $videoWidth, Video Height: $videoHeight');
return GestureDetector(
onTap: toggleVideoPlay,
child: Column(
@ -82,10 +77,14 @@ class _VideoPlayerLibAvControlState extends State<VideoPlayerLibAvControl> {
SizedBox(
width: videoWidth,
height: videoHeight,
child: AspectRatio(
aspectRatio: videoPlayerController.value.aspectRatio,
child: VideoPlayer(videoPlayerController),
),
child: needsToLoad
? Container(
color: Colors.black,
)
: AspectRatio(
aspectRatio: videoPlayerController.value.aspectRatio,
child: VideoPlayer(videoPlayerController),
),
),
Row(
children: [