This commit is contained in:
147
lib/widgets/video_controls_overlay.dart
Normal file
147
lib/widgets/video_controls_overlay.dart
Normal file
@ -0,0 +1,147 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
|
||||
|
||||
class VideoControlsOverlay extends StatelessWidget {
|
||||
final CachedVideoPlayerPlusController controller;
|
||||
final VoidCallback onOverlayTap;
|
||||
final bool muted;
|
||||
final VoidCallback onMuteToggle;
|
||||
|
||||
const VideoControlsOverlay({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onOverlayTap,
|
||||
required this.muted,
|
||||
required this.onMuteToggle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_ControlButton(Icons.replay_10, () {
|
||||
onOverlayTap();
|
||||
Duration newPosition =
|
||||
controller.value.position - const Duration(seconds: 10);
|
||||
if (newPosition < Duration.zero) newPosition = Duration.zero;
|
||||
controller.seekTo(newPosition);
|
||||
}),
|
||||
const SizedBox(width: 40),
|
||||
_ControlButton(
|
||||
controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
|
||||
() {
|
||||
onOverlayTap();
|
||||
controller.value.isPlaying
|
||||
? controller.pause()
|
||||
: controller.play();
|
||||
},
|
||||
size: 64,
|
||||
),
|
||||
const SizedBox(width: 40),
|
||||
_ControlButton(Icons.forward_10, () {
|
||||
onOverlayTap();
|
||||
Duration newPosition =
|
||||
controller.value.position + const Duration(seconds: 10);
|
||||
if (newPosition > controller.value.duration) {
|
||||
newPosition = controller.value.duration;
|
||||
}
|
||||
controller.seekTo(newPosition);
|
||||
}),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
right: 12,
|
||||
bottom: 12,
|
||||
child: _ControlButton(muted ? Icons.volume_off : Icons.volume_up, () {
|
||||
onOverlayTap();
|
||||
onMuteToggle();
|
||||
}, size: 16),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 0),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned(
|
||||
left: 10,
|
||||
bottom: 12,
|
||||
child: Text(
|
||||
'${_formatDuration(controller.value.position)} / ${_formatDuration(controller.value.duration)}',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
),
|
||||
Listener(
|
||||
onPointerDown: (_) {
|
||||
onOverlayTap();
|
||||
},
|
||||
child: VideoProgressIndicator(
|
||||
controller,
|
||||
allowScrubbing: true,
|
||||
padding: const EdgeInsets.only(top: 25.0),
|
||||
colors: const VideoProgressColors(
|
||||
playedColor: Colors.red,
|
||||
backgroundColor: Colors.grey,
|
||||
bufferedColor: Colors.white54,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (controller.value.duration.inMilliseconds > 0)
|
||||
Positioned(
|
||||
left:
|
||||
(controller.value.position.inMilliseconds /
|
||||
controller.value.duration.inMilliseconds) *
|
||||
MediaQuery.of(context).size.width -
|
||||
6,
|
||||
bottom: -4,
|
||||
child: Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.red,
|
||||
border: Border.all(color: Colors.red, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDuration(Duration duration) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
||||
return "${twoDigits(duration.inMinutes % 60)}:${twoDigits(duration.inSeconds % 60)}";
|
||||
}
|
||||
}
|
||||
|
||||
class _ControlButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final VoidCallback onPressed;
|
||||
final double size;
|
||||
|
||||
const _ControlButton(this.icon, this.onPressed, {this.size = 24});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.black.withValues(alpha: 0.4),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(icon, size: size),
|
||||
onPressed: onPressed,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user