mirror of
https://github.com/amigan/calls.git
synced 2024-11-22 04:49:49 -05:00
playqueue works!
This commit is contained in:
parent
74cc279069
commit
e4072458db
3 changed files with 14 additions and 12 deletions
|
@ -22,6 +22,7 @@ class Stillbox extends ChangeNotifier {
|
||||||
Uri? baseUri = Uri.base;
|
Uri? baseUri = Uri.base;
|
||||||
int queueLen = 0;
|
int queueLen = 0;
|
||||||
final StreamController<SBCall> callStream = StreamController<SBCall>();
|
final StreamController<SBCall> callStream = StreamController<SBCall>();
|
||||||
|
final StreamController<int> callQStream = StreamController<int>();
|
||||||
|
|
||||||
set state(LiveState newState) {
|
set state(LiveState newState) {
|
||||||
channel.sink.add(Live(state: newState, filter: currentFilter));
|
channel.sink.add(Live(state: newState, filter: currentFilter));
|
||||||
|
@ -110,8 +111,8 @@ class Stillbox extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatchCall(SBCall call) {
|
void dispatchCall(SBCall call) {
|
||||||
queueLen++;
|
|
||||||
callStream.add(call);
|
callStream.add(call);
|
||||||
|
callQStream.add(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleData(dynamic event) {
|
void _handleData(dynamic event) {
|
||||||
|
|
|
@ -14,12 +14,10 @@ class JustAudioDriver {
|
||||||
initializer.audioInit();
|
initializer.audioInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<justaudio.PlayerState> get playerStateStream {
|
Stream<justaudio.PlayerState> get playerStateStream {
|
||||||
return player.playerStateStream;
|
return player.playerStateStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> play(Call call) async {
|
Future<void> play(Call call) async {
|
||||||
player.setAudioSource(CallBytesSource(call));
|
player.setAudioSource(CallBytesSource(call));
|
||||||
await player.play();
|
await player.play();
|
||||||
|
|
|
@ -27,22 +27,28 @@ class _MainRadioState extends State<MainRadio> {
|
||||||
Timer? _lcdTimer;
|
Timer? _lcdTimer;
|
||||||
SBCall? _call;
|
SBCall? _call;
|
||||||
Completer _completer = Completer();
|
Completer _completer = Completer();
|
||||||
|
int queueLen = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final sb = Provider.of<Stillbox>(context, listen: false);
|
final sb = Provider.of<Stillbox>(context, listen: false);
|
||||||
player.player.playerStateStream.listen((event) async {
|
player.player.playerStateStream.listen((event) async {
|
||||||
if (!event.playing &&
|
if (event.processingState == ProcessingState.completed &&
|
||||||
event.processingState == ProcessingState.completed) {
|
!_completer.isCompleted) {
|
||||||
_completer.complete();
|
_completer.complete();
|
||||||
setState(() {
|
setState(() {
|
||||||
_ledColor = Colors.black;
|
_ledColor = Colors.black;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
sb.callQStream.stream.listen((ctAdd) {
|
||||||
|
setState(() {
|
||||||
|
queueLen += ctAdd;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
_callLoop(sb);
|
_callLoop(sb);
|
||||||
// sb.callStream.stream.listen((call) async {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _callLoop(Stillbox sb) async {
|
void _callLoop(Stillbox sb) async {
|
||||||
|
@ -50,13 +56,11 @@ class _MainRadioState extends State<MainRadio> {
|
||||||
lcdOn();
|
lcdOn();
|
||||||
setState(() {
|
setState(() {
|
||||||
_call = call;
|
_call = call;
|
||||||
sb.queueLen--;
|
queueLen--;
|
||||||
});
|
});
|
||||||
print("bef" + DateTime.now().toString());
|
|
||||||
_completer = Completer();
|
_completer = Completer();
|
||||||
await player.play(call.call);
|
player.play(call.call);
|
||||||
await _completer.future;
|
await _completer.future;
|
||||||
print("aft" + DateTime.now().toString());
|
|
||||||
lcdOff();
|
lcdOff();
|
||||||
} //);
|
} //);
|
||||||
}
|
}
|
||||||
|
@ -100,8 +104,7 @@ class _MainRadioState extends State<MainRadio> {
|
||||||
const ScannerLabel('Stillbox'),
|
const ScannerLabel('Stillbox'),
|
||||||
LED(_ledColor),
|
LED(_ledColor),
|
||||||
]),
|
]),
|
||||||
LCD(_call, _lcdColor,
|
LCD(_call, _lcdColor, queueLen),
|
||||||
Provider.of<Stillbox>(context, listen: false).queueLen),
|
|
||||||
const Keypad(),
|
const Keypad(),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
|
|
Loading…
Reference in a new issue