✨ Buffered progress display
This commit is contained in:
parent
2751ab1296
commit
7e7df4dc46
@ -13,12 +13,13 @@ import 'package:rhythm_box/services/audio_services/image.dart';
|
|||||||
import 'package:rhythm_box/widgets/tracks/querying_track_info.dart';
|
import 'package:rhythm_box/widgets/tracks/querying_track_info.dart';
|
||||||
|
|
||||||
class PlayerScreen extends StatefulWidget {
|
class PlayerScreen extends StatefulWidget {
|
||||||
final Duration durationCurrent, durationTotal;
|
final Duration durationCurrent, durationTotal, durationBuffered;
|
||||||
|
|
||||||
const PlayerScreen({
|
const PlayerScreen({
|
||||||
super.key,
|
super.key,
|
||||||
required this.durationCurrent,
|
required this.durationCurrent,
|
||||||
required this.durationTotal,
|
required this.durationTotal,
|
||||||
|
required this.durationBuffered,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -38,6 +39,8 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
|||||||
bool get _isPlaying => _playback.isPlaying.value;
|
bool get _isPlaying => _playback.isPlaying.value;
|
||||||
bool get _isFetchingActiveTrack => _query.isQueryingTrackInfo.value;
|
bool get _isFetchingActiveTrack => _query.isQueryingTrackInfo.value;
|
||||||
|
|
||||||
|
double _bufferProgress = 0;
|
||||||
|
|
||||||
Duration _durationCurrent = Duration.zero;
|
Duration _durationCurrent = Duration.zero;
|
||||||
Duration _durationTotal = Duration.zero;
|
Duration _durationTotal = Duration.zero;
|
||||||
|
|
||||||
@ -75,9 +78,14 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
_durationCurrent = widget.durationCurrent;
|
_durationCurrent = widget.durationCurrent;
|
||||||
_durationTotal = widget.durationTotal;
|
_durationTotal = widget.durationTotal;
|
||||||
|
_bufferProgress = widget.durationBuffered.inMilliseconds.toDouble();
|
||||||
_subscriptions = [
|
_subscriptions = [
|
||||||
audioPlayer.durationStream.listen(_updateDurationTotal),
|
audioPlayer.durationStream
|
||||||
audioPlayer.positionStream.listen(_updateDurationCurrent),
|
.listen((dur) => setState(() => _durationTotal = dur)),
|
||||||
|
audioPlayer.positionStream
|
||||||
|
.listen((dur) => setState(() => _durationCurrent = dur)),
|
||||||
|
audioPlayer.bufferedPositionStream.listen((dur) =>
|
||||||
|
setState(() => _bufferProgress = dur.inMilliseconds.toDouble())),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +162,14 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
|||||||
overlayShape: SliderComponentShape.noOverlay,
|
overlayShape: SliderComponentShape.noOverlay,
|
||||||
),
|
),
|
||||||
child: Slider(
|
child: Slider(
|
||||||
value: _draggingValue ??
|
secondaryTrackValue: _bufferProgress.abs(),
|
||||||
|
value: _draggingValue?.abs() ??
|
||||||
(_durationCurrent.inMilliseconds <=
|
(_durationCurrent.inMilliseconds <=
|
||||||
_durationTotal.inMilliseconds
|
_durationTotal.inMilliseconds
|
||||||
? _durationCurrent.inMilliseconds.toDouble()
|
? _durationCurrent.inMilliseconds.toDouble().abs()
|
||||||
: 0),
|
: 0),
|
||||||
min: 0,
|
min: 0,
|
||||||
max: _durationTotal.inMilliseconds.toDouble(),
|
max: _durationTotal.inMilliseconds.abs().toDouble(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() => _draggingValue = value);
|
setState(() => _draggingValue = value);
|
||||||
},
|
},
|
||||||
|
@ -45,6 +45,7 @@ class _BottomPlayerState extends State<BottomPlayer>
|
|||||||
|
|
||||||
Duration _durationCurrent = Duration.zero;
|
Duration _durationCurrent = Duration.zero;
|
||||||
Duration _durationTotal = Duration.zero;
|
Duration _durationTotal = Duration.zero;
|
||||||
|
Duration _durationBuffered = Duration.zero;
|
||||||
|
|
||||||
void _updateDurationCurrent(Duration dur) {
|
void _updateDurationCurrent(Duration dur) {
|
||||||
setState(() => _durationCurrent = dur);
|
setState(() => _durationCurrent = dur);
|
||||||
@ -70,8 +71,12 @@ class _BottomPlayerState extends State<BottomPlayer>
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_subscriptions = [
|
_subscriptions = [
|
||||||
audioPlayer.durationStream.listen(_updateDurationTotal),
|
audioPlayer.durationStream
|
||||||
audioPlayer.positionStream.listen(_updateDurationCurrent),
|
.listen((dur) => setState(() => _durationTotal = dur)),
|
||||||
|
audioPlayer.positionStream
|
||||||
|
.listen((dur) => setState(() => _durationCurrent = dur)),
|
||||||
|
audioPlayer.bufferedPositionStream
|
||||||
|
.listen((dur) => setState(() => _durationBuffered = dur)),
|
||||||
_playback.state.listen((state) {
|
_playback.state.listen((state) {
|
||||||
if (state.playlist.medias.isNotEmpty && !_isLifted) {
|
if (state.playlist.medias.isNotEmpty && !_isLifted) {
|
||||||
_animationController.animateTo(1);
|
_animationController.animateTo(1);
|
||||||
@ -183,6 +188,7 @@ class _BottomPlayerState extends State<BottomPlayer>
|
|||||||
context.pushTransparentRoute(PlayerScreen(
|
context.pushTransparentRoute(PlayerScreen(
|
||||||
durationCurrent: _durationCurrent,
|
durationCurrent: _durationCurrent,
|
||||||
durationTotal: _durationTotal,
|
durationTotal: _durationTotal,
|
||||||
|
durationBuffered: _durationBuffered,
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user