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

Allow video zooming with InteractiveViewer widget. #617

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ class ChewieController extends ChangeNotifier {
this.optionsBuilder,
this.additionalOptions,
this.showControls = true,
this.zoomAndPan = false,
this.maxScale = 2.5,
this.subtitle,
this.subtitleBuilder,
this.customControls,
Expand Down Expand Up @@ -303,6 +305,8 @@ class ChewieController extends ChangeNotifier {
Future<void> Function(BuildContext, List<OptionItem>)? optionsBuilder,
List<OptionItem> Function(BuildContext)? additionalOptions,
bool? showControls,
bool? zoomAndPan,
double? maxScale,
Subtitles? subtitle,
Widget Function(BuildContext, dynamic)? subtitleBuilder,
Widget? customControls,
Expand Down Expand Up @@ -426,6 +430,12 @@ class ChewieController extends ChangeNotifier {
/// Whether or not to show the controls at all
final bool showControls;

/// Whether or not to allow zooming and panning
final bool zoomAndPan;

/// Max scale when zooming
final double maxScale;

/// Defines customised controls. Check [MaterialControls] or
/// [CupertinoControls] for reference.
final Widget? customControls;
Expand Down
34 changes: 21 additions & 13 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ class PlayerWithControls extends StatelessWidget {
children: <Widget>[
if (chewieController.placeholder != null)
chewieController.placeholder!,
Center(
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
InteractiveViewer(
maxScale: chewieController.maxScale,
panEnabled: chewieController.zoomAndPan,
scaleEnabled: chewieController.zoomAndPan,
child: Center(
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
),
),
),
if (chewieController.overlay != null) chewieController.overlay!,
Expand All @@ -52,14 +57,17 @@ class PlayerWithControls extends StatelessWidget {
PlayerNotifier notifier,
Widget? widget,
) =>
AnimatedOpacity(
opacity: notifier.hideStuff ? 0.0 : 0.8,
duration: const Duration(
milliseconds: 250,
),
child: Container(
decoration: const BoxDecoration(color: Colors.black54),
child: Container(),
Visibility(
visible: !notifier.hideStuff,
child: AnimatedOpacity(
opacity: notifier.hideStuff ? 0.0 : 0.8,
duration: const Duration(
milliseconds: 250,
),
child: Container(
decoration: const BoxDecoration(color: Colors.black54),
child: Container(),
),
),
),
),
Expand Down