From e4072458db08bb89ec13543d0973ea734d443d79 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 18 Aug 2024 09:17:10 -0400 Subject: [PATCH] playqueue works! --- lib/controller/stillbox.dart | 3 ++- lib/views/play.dart | 2 -- lib/views/radio.dart | 21 ++++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/controller/stillbox.dart b/lib/controller/stillbox.dart index df34b80..4029bc9 100644 --- a/lib/controller/stillbox.dart +++ b/lib/controller/stillbox.dart @@ -22,6 +22,7 @@ class Stillbox extends ChangeNotifier { Uri? baseUri = Uri.base; int queueLen = 0; final StreamController callStream = StreamController(); + final StreamController callQStream = StreamController(); set state(LiveState newState) { channel.sink.add(Live(state: newState, filter: currentFilter)); @@ -110,8 +111,8 @@ class Stillbox extends ChangeNotifier { } void dispatchCall(SBCall call) { - queueLen++; callStream.add(call); + callQStream.add(1); } void _handleData(dynamic event) { diff --git a/lib/views/play.dart b/lib/views/play.dart index 7cbb9c6..3da4d50 100644 --- a/lib/views/play.dart +++ b/lib/views/play.dart @@ -14,12 +14,10 @@ class JustAudioDriver { initializer.audioInit(); } - @override Stream get playerStateStream { return player.playerStateStream; } - @override Future play(Call call) async { player.setAudioSource(CallBytesSource(call)); await player.play(); diff --git a/lib/views/radio.dart b/lib/views/radio.dart index 86577bb..cfdf9b0 100644 --- a/lib/views/radio.dart +++ b/lib/views/radio.dart @@ -27,22 +27,28 @@ class _MainRadioState extends State { Timer? _lcdTimer; SBCall? _call; Completer _completer = Completer(); + int queueLen = 0; @override void initState() { super.initState(); final sb = Provider.of(context, listen: false); player.player.playerStateStream.listen((event) async { - if (!event.playing && - event.processingState == ProcessingState.completed) { + if (event.processingState == ProcessingState.completed && + !_completer.isCompleted) { _completer.complete(); setState(() { _ledColor = Colors.black; }); } }); + sb.callQStream.stream.listen((ctAdd) { + setState(() { + queueLen += ctAdd; + }); + }); + _callLoop(sb); - // sb.callStream.stream.listen((call) async { } void _callLoop(Stillbox sb) async { @@ -50,13 +56,11 @@ class _MainRadioState extends State { lcdOn(); setState(() { _call = call; - sb.queueLen--; + queueLen--; }); - print("bef" + DateTime.now().toString()); _completer = Completer(); - await player.play(call.call); + player.play(call.call); await _completer.future; - print("aft" + DateTime.now().toString()); lcdOff(); } //); } @@ -100,8 +104,7 @@ class _MainRadioState extends State { const ScannerLabel('Stillbox'), LED(_ledColor), ]), - LCD(_call, _lcdColor, - Provider.of(context, listen: false).queueLen), + LCD(_call, _lcdColor, queueLen), const Keypad(), ], )),