This commit is contained in:
@ -1,6 +1,10 @@
|
||||
import 'package:f0ckapp/models/mediaitem.dart';
|
||||
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';
|
||||
|
||||
class VideoWidget extends StatefulWidget {
|
||||
final MediaItem details;
|
||||
@ -12,6 +16,7 @@ class VideoWidget extends StatefulWidget {
|
||||
|
||||
class _VideoWidgetState extends State<VideoWidget> {
|
||||
late VideoPlayerController _controller;
|
||||
bool _showControls = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -37,13 +42,6 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isAudio = widget.details.mime.startsWith('audio');
|
||||
@ -61,115 +59,38 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_controller.value.isPlaying
|
||||
? _controller.pause()
|
||||
: _controller.play();
|
||||
_showControls = !_showControls;
|
||||
});
|
||||
},
|
||||
child: isAudio
|
||||
? Image.network(widget.details.coverUrl, fit: BoxFit.cover)
|
||||
? CachedNetworkImage(
|
||||
imageUrl: widget.details.coverUrl,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) =>
|
||||
CircularProgressIndicator(),
|
||||
errorWidget: (context, url, error) => Image.network(
|
||||
"https://f0ck.me/s/img/music.webp",
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
)
|
||||
: _controller.value.isInitialized
|
||||
? VideoPlayer(_controller)
|
||||
: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
if (_controller.value.isInitialized)
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Stack(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 10,
|
||||
child: VideoProgressIndicator(
|
||||
_controller,
|
||||
allowScrubbing: true,
|
||||
padding: EdgeInsets.only(bottom: 0),
|
||||
colors: VideoProgressColors(
|
||||
playedColor: Colors.red,
|
||||
bufferedColor: Colors.grey,
|
||||
backgroundColor: Colors.black.withAlpha(128),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left:
|
||||
(_controller.value.position.inMilliseconds /
|
||||
_controller.value.duration.inMilliseconds) *
|
||||
MediaQuery.of(context).size.width -
|
||||
6,
|
||||
bottom: -1,
|
||||
child: Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
border: Border.all(color: Colors.red, width: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
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),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_controller.value.isInitialized)
|
||||
SizedBox(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_formatDuration(_controller.value.position),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.replay_10),
|
||||
color: Colors.white,
|
||||
onPressed: () {
|
||||
_controller.seekTo(
|
||||
_controller.value.position -
|
||||
const Duration(seconds: 10),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: Icon(
|
||||
_controller.value.isPlaying
|
||||
? Icons.pause
|
||||
: Icons.play_arrow,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_controller.value.isPlaying
|
||||
? _controller.pause()
|
||||
: _controller.play();
|
||||
});
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
color: Colors.white,
|
||||
icon: const Icon(Icons.forward_10),
|
||||
onPressed: () {
|
||||
_controller.seekTo(
|
||||
_controller.value.position +
|
||||
const Duration(seconds: 10),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
_formatDuration(_controller.value.duration),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user