I have been having an issue with Chewie player to display the video correctly,kindly guide how to display the original video aspect ratio in full screen without stretching or cropping.
Whenever I put BoxFit.contain
, the video display original aspect ration inside the player with black bars not full screen.
When I put BoxFit.cover
, it becomes full screen however video stretched and original video quality is lost.
Please suggest how do I display in full screen size and original quality. Please suggest how to do 2 step zoom like Jiohotstar.
I try changing the code but did not get my solutions I'm seeking.
This is my player_with_controls.dart file
import 'package:chewie/src/chewie_player.dart';
import 'package:chewie/src/helpers/adaptive_controls.dart';
import 'package:chewie/src/notifiers/index.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';
class PlayerWithControls extends StatelessWidget {
const PlayerWithControls({super.key});
@override
Widget build(BuildContext context) {
final ChewieController chewieController = ChewieController.of(context);
double calculateAspectRatio(BuildContext context) {
final size = MediaQuery.of(context).size;
final width = size.width;
final height = size.height;
return width > height ? width / height : height / width;
}
Widget buildControls(
BuildContext context,
ChewieController chewieController,
) {
return chewieController.showControls
? chewieController.customControls ?? const AdaptiveControls()
: const SizedBox();
}
Widget buildPlayerWithControls(
ChewieController chewieController,
BuildContext context,
) {
return Stack(
children: <Widget>[
if (chewieController.placeholder != null)
chewieController.placeholder!,
InteractiveViewer(
transformationController: chewieController.transformationController,
maxScale: chewieController.maxScale,
panEnabled: chewieController.zoomAndPan,
scaleEnabled: chewieController.zoomAndPan,
child: SizedBox.expand(
child: FittedBox(
fit: chewieController.isFullScreen ? BoxFit.contain : BoxFit.fitWidth,
child: SizedBox(
width: chewieController.videoPlayerController.value.size.width,
height: chewieController.videoPlayerController.value.size.height,
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ?? chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
),
),
),
),
),
if (chewieController.overlay != null) chewieController.overlay!,
if (Theme.of(context).platform != TargetPlatform.iOS)
Consumer<PlayerNotifier>(
builder: (
BuildContext context,
PlayerNotifier notifier,
Widget? widget,
) =>
Visibility(
visible: !notifier.hideStuff,
child: AnimatedOpacity(
opacity: notifier.hideStuff ? 0.0 : 0.8,
duration: const Duration(
milliseconds: 250,
),
child: const DecoratedBox(
decoration: BoxDecoration(color: Colors.black54),
child: SizedBox.expand(),
),
),
),
),
if (!chewieController.isFullScreen)
buildControls(context, chewieController)
else
SafeArea(
bottom: false,
child: buildControls(context, chewieController),
),
],
);
}
return Center(
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: AspectRatio(
aspectRatio: calculateAspectRatio(context),
child: buildPlayerWithControls(chewieController, context),
),
),
);
}
}