Skip to content

Commit

Permalink
chore: improve hiding controls mechanism for video container in yt mi…
Browse files Browse the repository at this point in the history
…niplayer
  • Loading branch information
MSOB7YY committed Aug 17, 2024
1 parent f7b6090 commit c00c162
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/controller/video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'package:namida/youtube/widgets/yt_thumbnail.dart';

class NamidaVideoWidget extends StatelessWidget {
final bool enableControls;
final double? disableControlsUnderPercentage;
final VoidCallback? onMinimizeTap;
final bool fullscreen;
final bool isPip;
Expand All @@ -39,7 +40,8 @@ class NamidaVideoWidget extends StatelessWidget {

const NamidaVideoWidget({
super.key,
required this.enableControls,
this.enableControls = true,
this.disableControlsUnderPercentage,
this.onMinimizeTap,
this.fullscreen = false,
this.isPip = false,
Expand Down Expand Up @@ -111,6 +113,7 @@ class NamidaVideoWidget extends StatelessWidget {
}
},
showControls: showControls,
disableControlsUnderPercentage: disableControlsUnderPercentage,
isFullScreen: fullscreen,
),
),
Expand All @@ -126,12 +129,14 @@ class VideoController {
final videoZoomAdditionalScale = 0.0.obs;

void updateShouldShowControls(double animationValue) {
final ytmini = videoControlsKey.currentState;
if (ytmini == null) return;
final isExpanded = animationValue >= 0.95;
if (isExpanded) {
// YoutubeMiniplayerUiController.inst.startDimTimer(); // bad experience honestly
} else {
// YoutubeMiniplayerUiController.inst.cancelDimTimer();
videoControlsKey.currentState?.setControlsVisibily(false);
ytmini.setControlsVisibily(false);
}
}

Expand Down
25 changes: 24 additions & 1 deletion lib/ui/widgets/video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:youtipie/core/extensions.dart';
import 'package:namida/class/track.dart';
import 'package:namida/class/video.dart';
import 'package:namida/controller/current_color.dart';
import 'package:namida/controller/miniplayer_controller.dart';
import 'package:namida/controller/namida_channel.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/controller/player_controller.dart';
Expand Down Expand Up @@ -211,6 +212,22 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
await controller.animateTo(target);
}

/// disables controls entirely when specified. for example when minplayer is minimized & controls should't be there.
void _disableControlsListener() {
if (!mounted) return;
final value = MiniPlayerController.inst.animation.value;
final hideUnder = widget.disableControlsUnderPercentage!;
if (value < hideUnder && _isControlsEnabled) {
setState(() {
_isControlsEnabled = false;
});
} else if (value >= hideUnder && !_isControlsEnabled) {
setState(() {
_isControlsEnabled = true;
});
}
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -252,6 +269,10 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
},
);
}

if (widget.disableControlsUnderPercentage != null) {
MiniPlayerController.inst.animation.addListener(_disableControlsListener);
}
}

final _volumeListenerKey = 'video_widget';
Expand All @@ -265,6 +286,7 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
_currentDeviceVolume.close();
_canShowBrightnessSlider.close();
Player.inst.onVolumeChangeRemoveListener(_volumeListenerKey);
MiniPlayerController.inst.animation.removeListener(_disableControlsListener);
super.dispose();
}

Expand Down Expand Up @@ -530,7 +552,8 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
_doubleTapTimer = null;
}

bool get _canShowControls => widget.showControls && !NamidaChannel.inst.isInPip.value;
late bool _isControlsEnabled = widget.showControls;
bool get _canShowControls => _isControlsEnabled && !NamidaChannel.inst.isInPip.value;

EdgeInsets _deviceInsets = EdgeInsets.zero;

Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
height: finalthumbnailHeight,
child: NamidaVideoWidget(
isLocal: false,
enableControls: percentage > 0.5,
disableControlsUnderPercentage: 0.5,
onMinimizeTap: () => MiniPlayerController.inst.ytMiniplayerKey.currentState?.animateToState(false),
swipeUpToFullscreen: true,
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 3.9.28-beta+240817228
version: 3.9.29-beta+240817228

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit c00c162

Please sign in to comment.