Skip to content

Commit

Permalink
Introduce onMute and onUnmute methods for player mute detection
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Sogani <[email protected]>
  • Loading branch information
Siddharth2212 committed Jan 28, 2024
1 parent 62782b7 commit 763915a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 18 deletions.
17 changes: 15 additions & 2 deletions example/lib/animation_player/landscape_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ import 'package:provider/provider.dart';

class AnimationPlayerLandscapeControls extends StatelessWidget {
const AnimationPlayerLandscapeControls(
{Key? key, required this.animationPlayerDataManager})
{Key? key,
this.onMute,
this.onUnmute,
required this.animationPlayerDataManager})
: super(key: key);

final AnimationPlayerDataManager animationPlayerDataManager;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;

@override
Widget build(BuildContext context) {
FlickVideoManager flickVideoManager =
Expand Down Expand Up @@ -81,7 +90,11 @@ class AnimationPlayerLandscapeControls extends StatelessWidget {
SizedBox(
width: 10,
),
FlickSoundToggle(size: 30),
FlickSoundToggle(
size: 30,
onMute: onMute,
onUnmute: onUnmute,
),
SizedBox(
width: 20,
),
Expand Down
12 changes: 11 additions & 1 deletion example/lib/animation_player/portrait_video_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ class AnimationPlayerPortraitVideoControls extends StatelessWidget {
Key? key,
this.pauseOnTap,
this.dataManager,
this.onMute,
this.onUnmute,
}) : super(key: key);
final bool? pauseOnTap;
final AnimationPlayerDataManager? dataManager;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;
@override
Widget build(BuildContext context) {
FlickVideoManager flickVideoManager =
Expand Down Expand Up @@ -81,7 +88,10 @@ class AnimationPlayerPortraitVideoControls extends StatelessWidget {
FlickAutoHideChild(
autoHide: false,
showIfVideoNotInitialized: false,
child: FlickSoundToggle(),
child: FlickSoundToggle(
onMute: onMute,
onUnmute: onUnmute,
),
),
FlickAutoHideChild(
autoHide: false,
Expand Down
14 changes: 13 additions & 1 deletion example/lib/feed_player/portrait_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import './multi_manager/flick_multi_manager.dart';

class FeedPlayerPortraitControls extends StatelessWidget {
const FeedPlayerPortraitControls(
{Key? key, this.flickMultiManager, this.flickManager})
{Key? key,
this.flickMultiManager,
this.onMute,
this.onUnmute,
this.flickManager})
: super(key: key);

final FlickMultiManager? flickMultiManager;
final FlickManager? flickManager;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;

@override
Widget build(BuildContext context) {
FlickDisplayManager displayManager =
Expand Down Expand Up @@ -61,6 +71,8 @@ class FeedPlayerPortraitControls extends StatelessWidget {
child: FlickSoundToggle(
toggleMute: () => flickMultiManager?.toggleMute(),
color: Colors.white,
onMute: onMute,
onUnmute: onUnmute,
),
),
// FlickFullScreenToggle(),
Expand Down
15 changes: 13 additions & 2 deletions example/lib/landscape_player/landscape_player_controls.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@

import 'package:example/landscape_player/play_toggle.dart';
import 'package:flick_video_player/flick_video_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class LandscapePlayerControls extends StatelessWidget {
const LandscapePlayerControls(
{Key? key, this.iconSize = 20, this.fontSize = 12})
{Key? key,
this.iconSize = 20,
this.onMute,
this.onUnmute,
this.fontSize = 12})
: super(key: key);
final double iconSize;
final double fontSize;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;

@override
Widget build(BuildContext context) {
return Stack(
Expand Down Expand Up @@ -116,6 +125,8 @@ class LandscapePlayerControls extends StatelessWidget {
),
FlickSoundToggle(
size: 20,
onMute: onMute,
onUnmute: onUnmute,
),
],
),
Expand Down
10 changes: 10 additions & 0 deletions example/lib/web_video_player/web_video_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class WebVideoControl extends StatelessWidget {
{Key? key,
this.iconSize = 20,
this.fontSize = 12,
this.onMute,
this.onUnmute,
this.progressBarSettings,
this.dataManager})
: super(key: key);
Expand All @@ -21,6 +23,12 @@ class WebVideoControl extends StatelessWidget {
/// [dataManager] is used to handle video controls.
final DataManager? dataManager;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;

/// Font size.
///
/// This size is used for all the text.
Expand Down Expand Up @@ -124,6 +132,8 @@ class WebVideoControl extends StatelessWidget {
),
FlickSoundToggle(
size: iconSize,
onMute: onMute,
onUnmute: onUnmute,
),
SizedBox(
width: iconSize / 2,
Expand Down
10 changes: 10 additions & 0 deletions lib/src/controls/flick_portrait_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class FlickPortraitControls extends StatelessWidget {
{Key? key,
this.iconSize = 20,
this.fontSize = 12,
this.onMute,
this.onUnmute,
this.progressBarSettings})
: super(key: key);

Expand All @@ -15,6 +17,12 @@ class FlickPortraitControls extends StatelessWidget {
/// This size is used for all the player icons.
final double iconSize;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;

/// Font size.
///
/// This size is used for all the text.
Expand Down Expand Up @@ -70,6 +78,8 @@ class FlickPortraitControls extends StatelessWidget {
),
FlickSoundToggle(
size: iconSize,
onMute: onMute,
onUnmute: onUnmute,
),
SizedBox(
width: iconSize / 2,
Expand Down
38 changes: 26 additions & 12 deletions lib/src/widgets/flick_sound_toggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class FlickSoundToggle extends StatelessWidget {
Key? key,
this.muteChild,
this.unmuteChild,
this.onMute,
this.onUnmute,
this.toggleMute,
this.size,
this.color,
Expand All @@ -25,6 +27,12 @@ class FlickSoundToggle extends StatelessWidget {
/// Default - Icon(Icons.volume_up)
final Widget? unmuteChild;

/// This function is used for telling whatwill happen on mute press.
final VoidCallback? onMute;

/// This function is used for telling whatwill happen on unmute press.
final VoidCallback? onUnmute;

/// Function called onTap of visible child.
///
/// Default action -
Expand All @@ -50,18 +58,24 @@ class FlickSoundToggle extends StatelessWidget {
FlickControlManager controlManager =
Provider.of<FlickControlManager>(context);

Widget muteWidget = muteChild ??
Icon(
Icons.volume_off,
size: size,
color: color,
);
Widget unmuteWidget = unmuteChild ??
Icon(
Icons.volume_up,
size: size,
color: color,
);
Widget muteWidget = GestureDetector(
onTap: onMute == null ? () {} : onMute,
child: muteChild ??
Icon(
Icons.volume_off,
size: size,
color: color,
),
);
Widget unmuteWidget = GestureDetector(
onTap: onUnmute == null ? () {} : onUnmute,
child: unmuteChild ??
Icon(
Icons.volume_up,
size: size,
color: color,
),
);

Widget child = controlManager.isMute ? muteWidget : unmuteWidget;

Expand Down

0 comments on commit 763915a

Please sign in to comment.