Display media size

This commit is contained in:
Pierre HUBERT 2022-03-24 12:06:11 +01:00
parent 545d9a951f
commit 1ff98b7bbf

View File

@ -11,6 +11,12 @@ import 'package:music_web_player/api.dart';
import 'package:music_web_player/ui/cover_image.dart';
import 'package:video_player/video_player.dart';
extension DurationExt on Duration {
String get formatted {
return "$inMinutes:${(inSeconds % 60).toString().padLeft(2, '0')}";
}
}
class MusicPlayer extends StatefulWidget {
final MusicsList musicsList;
@ -167,12 +173,22 @@ class _MusicPlayerState extends State<MusicPlayer> {
const SizedBox(height: 20),
Text(currMusic.artist, textAlign: TextAlign.center),
const fluent.SizedBox(height: 40),
fluent.Slider(
fluent.Row(
children: [
DurationText(_position),
const SizedBox(width: 15),
Flexible(
child: fluent.Slider(
max: _duration?.inSeconds as double? ?? 0,
value: _position?.inSeconds as double? ?? 0,
onChanged: (d) => _updatePosition(Duration(seconds: d.toInt())),
label:
"${_position?.inMinutes.toString().padLeft(2, '0')} : ${((_position?.inSeconds ?? 0) % 60).toString().padLeft(2, '0')}",
onChanged: (d) =>
_updatePosition(Duration(seconds: d.toInt())),
label: _position?.formatted,
),
),
const SizedBox(width: 15),
DurationText(_duration),
],
),
const fluent.SizedBox(height: 40),
fluent.Row(
@ -210,3 +226,17 @@ class PlayerIcon extends StatelessWidget {
@override
Widget build(BuildContext context) => Icon(icon, size: 35);
}
class DurationText extends StatelessWidget {
final Duration? duration;
const DurationText(this.duration, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Text(
duration?.formatted ?? "0:00",
style: const TextStyle(fontSize: 10),
);
}
}