From 1ff98b7bbf238033254c530d29cf95083a5470f8 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Thu, 24 Mar 2022 12:06:11 +0100 Subject: [PATCH] Display media size --- lib/ui/music_player.dart | 42 ++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/ui/music_player.dart b/lib/ui/music_player.dart index 38c3989..d911e9a 100644 --- a/lib/ui/music_player.dart +++ b/lib/ui/music_player.dart @@ -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 { const SizedBox(height: 20), Text(currMusic.artist, textAlign: TextAlign.center), const fluent.SizedBox(height: 40), - 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')}", + 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?.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), + ); + } +}