This commit is contained in:
		@@ -3,7 +3,13 @@ import 'package:video_player/video_player.dart';
 | 
			
		||||
 | 
			
		||||
class VideoControlsOverlay extends StatelessWidget {
 | 
			
		||||
  final VideoPlayerController controller;
 | 
			
		||||
  const VideoControlsOverlay({super.key, required this.controller});
 | 
			
		||||
  final VoidCallback button;
 | 
			
		||||
 | 
			
		||||
  const VideoControlsOverlay({
 | 
			
		||||
    super.key,
 | 
			
		||||
    required this.controller,
 | 
			
		||||
    required this.button,
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
@@ -15,22 +21,25 @@ class VideoControlsOverlay extends StatelessWidget {
 | 
			
		||||
            mainAxisAlignment: MainAxisAlignment.center,
 | 
			
		||||
            children: [
 | 
			
		||||
              _ControlButton(Icons.replay_10, () {
 | 
			
		||||
                button();
 | 
			
		||||
                controller.seekTo(
 | 
			
		||||
                  controller.value.position - Duration(seconds: 10),
 | 
			
		||||
                );
 | 
			
		||||
              }),
 | 
			
		||||
              SizedBox(width: 32),
 | 
			
		||||
              SizedBox(width: 40),
 | 
			
		||||
              _ControlButton(
 | 
			
		||||
                controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
 | 
			
		||||
                () {
 | 
			
		||||
                  button();
 | 
			
		||||
                  controller.value.isPlaying
 | 
			
		||||
                      ? controller.pause()
 | 
			
		||||
                      : controller.play();
 | 
			
		||||
                },
 | 
			
		||||
                size: 64,
 | 
			
		||||
              ),
 | 
			
		||||
              SizedBox(width: 32),
 | 
			
		||||
              SizedBox(width: 40),
 | 
			
		||||
              _ControlButton(Icons.forward_10, () {
 | 
			
		||||
                button();
 | 
			
		||||
                controller.seekTo(
 | 
			
		||||
                  controller.value.position + Duration(seconds: 10),
 | 
			
		||||
                );
 | 
			
		||||
@@ -38,7 +47,7 @@ class VideoControlsOverlay extends StatelessWidget {
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
        _ProgressIndicator(controller: controller),
 | 
			
		||||
        _ProgressIndicator(controller: controller)
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
@@ -68,6 +77,7 @@ class _ControlButton extends StatelessWidget {
 | 
			
		||||
 | 
			
		||||
class _ProgressIndicator extends StatelessWidget {
 | 
			
		||||
  final VideoPlayerController controller;
 | 
			
		||||
 | 
			
		||||
  const _ProgressIndicator({required this.controller});
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@@ -77,18 +87,14 @@ class _ProgressIndicator extends StatelessWidget {
 | 
			
		||||
      child: Stack(
 | 
			
		||||
        clipBehavior: Clip.none,
 | 
			
		||||
        children: [
 | 
			
		||||
          Container(
 | 
			
		||||
            height: 20,
 | 
			
		||||
            alignment: Alignment.bottomCenter,
 | 
			
		||||
            color: Colors.transparent,
 | 
			
		||||
            child: VideoProgressIndicator(
 | 
			
		||||
              controller,
 | 
			
		||||
              allowScrubbing: true,
 | 
			
		||||
              colors: VideoProgressColors(
 | 
			
		||||
                playedColor: Colors.red,
 | 
			
		||||
                backgroundColor: Colors.grey,
 | 
			
		||||
                bufferedColor: Colors.white54,
 | 
			
		||||
              ),
 | 
			
		||||
          VideoProgressIndicator(
 | 
			
		||||
            controller,
 | 
			
		||||
            allowScrubbing: true,
 | 
			
		||||
            padding: const EdgeInsets.only(top: 25.0),
 | 
			
		||||
            colors: VideoProgressColors(
 | 
			
		||||
              playedColor: Colors.red,
 | 
			
		||||
              backgroundColor: Colors.grey,
 | 
			
		||||
              bufferedColor: Colors.white54,
 | 
			
		||||
            ),
 | 
			
		||||
          ),
 | 
			
		||||
          Positioned(
 | 
			
		||||
@@ -123,8 +129,6 @@ class _ProgressIndicator extends StatelessWidget {
 | 
			
		||||
 | 
			
		||||
  String _formatDuration(Duration duration) {
 | 
			
		||||
    String twoDigits(int n) => n.toString().padLeft(2, '0');
 | 
			
		||||
    final minutes = twoDigits(duration.inMinutes.remainder(60));
 | 
			
		||||
    final seconds = twoDigits(duration.inSeconds.remainder(60));
 | 
			
		||||
    return "$minutes:$seconds";
 | 
			
		||||
    return "${twoDigits(duration.inMinutes % 60)}:${twoDigits(duration.inSeconds % 60)}";
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -3,8 +3,8 @@ import 'dart:async';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:video_player/video_player.dart';
 | 
			
		||||
import 'package:cached_network_image/cached_network_image.dart';
 | 
			
		||||
import 'package:f0ckapp/models/mediaitem.dart';
 | 
			
		||||
import 'package:f0ckapp/widgets/video_overlay.dart';
 | 
			
		||||
import 'package:f0ckapp/models/MediaItem.dart';
 | 
			
		||||
import 'package:f0ckapp/widgets/VideoOverlay.dart';
 | 
			
		||||
 | 
			
		||||
class VideoWidget extends StatefulWidget {
 | 
			
		||||
  final MediaItem details;
 | 
			
		||||
@@ -17,6 +17,7 @@ class VideoWidget extends StatefulWidget {
 | 
			
		||||
class _VideoWidgetState extends State<VideoWidget> {
 | 
			
		||||
  late VideoPlayerController _controller;
 | 
			
		||||
  bool _showControls = false;
 | 
			
		||||
  Timer? _hideControlsTimer;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
@@ -39,9 +40,23 @@ class _VideoWidgetState extends State<VideoWidget> {
 | 
			
		||||
  @override
 | 
			
		||||
  void dispose() {
 | 
			
		||||
    _controller.dispose();
 | 
			
		||||
    _hideControlsTimer?.cancel();
 | 
			
		||||
    super.dispose();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _onTap({bool ctrlButton = false}) {
 | 
			
		||||
    if (!ctrlButton) {
 | 
			
		||||
      setState(() => _showControls = !_showControls);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (_showControls) {
 | 
			
		||||
      _hideControlsTimer?.cancel();
 | 
			
		||||
      _hideControlsTimer = Timer(Duration(seconds: 5), () {
 | 
			
		||||
        setState(() => _showControls = false);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    bool isAudio = widget.details.mime.startsWith('audio');
 | 
			
		||||
@@ -57,11 +72,7 @@ class _VideoWidgetState extends State<VideoWidget> {
 | 
			
		||||
            alignment: Alignment.center,
 | 
			
		||||
            children: [
 | 
			
		||||
              GestureDetector(
 | 
			
		||||
                onTap: () {
 | 
			
		||||
                  setState(() {
 | 
			
		||||
                    _showControls = !_showControls;
 | 
			
		||||
                  });
 | 
			
		||||
                },
 | 
			
		||||
                onTap: _onTap,
 | 
			
		||||
                child: isAudio
 | 
			
		||||
                    ? CachedNetworkImage(
 | 
			
		||||
                        imageUrl: widget.details.coverUrl,
 | 
			
		||||
@@ -78,15 +89,7 @@ class _VideoWidgetState extends State<VideoWidget> {
 | 
			
		||||
                    : Center(child: CircularProgressIndicator()),
 | 
			
		||||
              ),
 | 
			
		||||
              if (_controller.value.isInitialized && _showControls) ...[
 | 
			
		||||
                IgnorePointer(
 | 
			
		||||
                  ignoring: true,
 | 
			
		||||
                  child: Container(
 | 
			
		||||
                    color: Colors.black.withValues(alpha: 0.5),
 | 
			
		||||
                    width: double.infinity,
 | 
			
		||||
                    height: double.infinity,
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
                VideoControlsOverlay(controller: _controller),
 | 
			
		||||
                VideoControlsOverlay(controller: _controller, button: () => _onTap(ctrlButton: true)),
 | 
			
		||||
              ],
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
		Reference in New Issue
	
	Block a user