Skip to content

Commit c00c162

Browse files
committed
chore: improve hiding controls mechanism for video container in yt miniplayer
1 parent f7b6090 commit c00c162

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

lib/controller/video_controller.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import 'package:namida/youtube/widgets/yt_thumbnail.dart';
3030

3131
class NamidaVideoWidget extends StatelessWidget {
3232
final bool enableControls;
33+
final double? disableControlsUnderPercentage;
3334
final VoidCallback? onMinimizeTap;
3435
final bool fullscreen;
3536
final bool isPip;
@@ -39,7 +40,8 @@ class NamidaVideoWidget extends StatelessWidget {
3940

4041
const NamidaVideoWidget({
4142
super.key,
42-
required this.enableControls,
43+
this.enableControls = true,
44+
this.disableControlsUnderPercentage,
4345
this.onMinimizeTap,
4446
this.fullscreen = false,
4547
this.isPip = false,
@@ -111,6 +113,7 @@ class NamidaVideoWidget extends StatelessWidget {
111113
}
112114
},
113115
showControls: showControls,
116+
disableControlsUnderPercentage: disableControlsUnderPercentage,
114117
isFullScreen: fullscreen,
115118
),
116119
),
@@ -126,12 +129,14 @@ class VideoController {
126129
final videoZoomAdditionalScale = 0.0.obs;
127130

128131
void updateShouldShowControls(double animationValue) {
132+
final ytmini = videoControlsKey.currentState;
133+
if (ytmini == null) return;
129134
final isExpanded = animationValue >= 0.95;
130135
if (isExpanded) {
131136
// YoutubeMiniplayerUiController.inst.startDimTimer(); // bad experience honestly
132137
} else {
133138
// YoutubeMiniplayerUiController.inst.cancelDimTimer();
134-
videoControlsKey.currentState?.setControlsVisibily(false);
139+
ytmini.setControlsVisibily(false);
135140
}
136141
}
137142

lib/ui/widgets/video_widget.dart

+24-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:youtipie/core/extensions.dart';
1313
import 'package:namida/class/track.dart';
1414
import 'package:namida/class/video.dart';
1515
import 'package:namida/controller/current_color.dart';
16+
import 'package:namida/controller/miniplayer_controller.dart';
1617
import 'package:namida/controller/namida_channel.dart';
1718
import 'package:namida/controller/navigator_controller.dart';
1819
import 'package:namida/controller/player_controller.dart';
@@ -211,6 +212,22 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
211212
await controller.animateTo(target);
212213
}
213214

215+
/// disables controls entirely when specified. for example when minplayer is minimized & controls should't be there.
216+
void _disableControlsListener() {
217+
if (!mounted) return;
218+
final value = MiniPlayerController.inst.animation.value;
219+
final hideUnder = widget.disableControlsUnderPercentage!;
220+
if (value < hideUnder && _isControlsEnabled) {
221+
setState(() {
222+
_isControlsEnabled = false;
223+
});
224+
} else if (value >= hideUnder && !_isControlsEnabled) {
225+
setState(() {
226+
_isControlsEnabled = true;
227+
});
228+
}
229+
}
230+
214231
@override
215232
void initState() {
216233
super.initState();
@@ -252,6 +269,10 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
252269
},
253270
);
254271
}
272+
273+
if (widget.disableControlsUnderPercentage != null) {
274+
MiniPlayerController.inst.animation.addListener(_disableControlsListener);
275+
}
255276
}
256277

257278
final _volumeListenerKey = 'video_widget';
@@ -265,6 +286,7 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
265286
_currentDeviceVolume.close();
266287
_canShowBrightnessSlider.close();
267288
Player.inst.onVolumeChangeRemoveListener(_volumeListenerKey);
289+
MiniPlayerController.inst.animation.removeListener(_disableControlsListener);
268290
super.dispose();
269291
}
270292

@@ -530,7 +552,8 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
530552
_doubleTapTimer = null;
531553
}
532554

533-
bool get _canShowControls => widget.showControls && !NamidaChannel.inst.isInPip.value;
555+
late bool _isControlsEnabled = widget.showControls;
556+
bool get _canShowControls => _isControlsEnabled && !NamidaChannel.inst.isInPip.value;
534557

535558
EdgeInsets _deviceInsets = EdgeInsets.zero;
536559

lib/youtube/youtube_miniplayer.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
12841284
height: finalthumbnailHeight,
12851285
child: NamidaVideoWidget(
12861286
isLocal: false,
1287-
enableControls: percentage > 0.5,
1287+
disableControlsUnderPercentage: 0.5,
12881288
onMinimizeTap: () => MiniPlayerController.inst.ytMiniplayerKey.currentState?.animateToState(false),
12891289
swipeUpToFullscreen: true,
12901290
),

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: namida
22
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
33
publish_to: "none"
4-
version: 3.9.28-beta+240817228
4+
version: 3.9.29-beta+240817228
55

66
environment:
77
sdk: ">=3.4.0 <4.0.0"

0 commit comments

Comments
 (0)