calls/lib/views/radio.dart

147 lines
3.7 KiB
Dart
Raw Normal View History

2024-08-17 16:51:47 -04:00
import 'dart:async';
2024-08-10 13:27:12 -04:00
import 'package:flutter/material.dart';
2024-08-20 09:11:21 -04:00
import 'package:intl/intl.dart';
2024-08-17 16:51:47 -04:00
import 'package:provider/provider.dart';
import 'package:just_audio/just_audio.dart';
2024-10-14 11:42:48 -04:00
import 'package:audio_session/audio_session.dart';
Something mostly working. Squashed commit of the following: commit b15263546eadbc86de233996c5c32ceb17e0a45d Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 09:29:49 2024 -0400 save bytes source class commit 3a6ac8868583a286c28f3d3de8b9a42ac52c5ba5 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 09:26:28 2024 -0400 safearea commit c411a007e62d4bb4551ce7f142ce7c3ef02485f9 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:33:11 2024 -0400 try to play commit 5a8e7c7690d803a1d676a7e4a30ef9807cd17294 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:29:53 2024 -0400 protoc commit c776d37765b522b0ac87e3b5efb5561e65a218a6 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:28:26 2024 -0400 wip commit 0d150d73d8f2631b7f6669e935ec212bbfb98ef8 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 23:07:35 2024 -0400 big huge wip commit db99eeb43ad35259d3bc998d63afd94e8bcf84b5 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 21:03:42 2024 -0400 big wip commit 5af1b90ccca175566c3bfad397dbd7b14e08cee7 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 20:04:37 2024 -0400 WIP commit 08183de44f347e2962b2a5830b920ce3bad08a7a Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 10:41:06 2024 -0400 notifier commit 5f92cf977ba657b94c623b891421169ce6d887fd Author: Daniel Ponte <amigan@gmail.com> Date: Mon Aug 12 09:13:43 2024 -0400 wip commit d6d590684d091d4746743fe8a77ee548e88a3f17 Author: Daniel Ponte <amigan@gmail.com> Date: Mon Aug 12 07:47:08 2024 -0400 fix commit 9d58f4fa7f75fccd88e8720af5e6aa1668bbb403 Author: Daniel Ponte <amigan@gmail.com> Date: Sun Aug 11 23:59:01 2024 -0400 wip commit d61ce79c295d965f457138e928b03aae4e3e6a6d Author: Daniel Ponte <amigan@gmail.com> Date: Sun Aug 11 19:23:16 2024 -0400 wip commit f4ea5916b8ca4361aaaddc4e4e1842e8328747a6 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 17:07:52 2024 -0400 macos stuff commit fe8bdc13a5ea12b10eb4110158aa7248ff851889 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 17:07:04 2024 -0400 add default case commit 9bc788035b1ba3c576a3ee1c7120259e727e24a2 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 16:38:46 2024 -0400 wip commit 8e99afeb31f7bba36264347ad11aed0ce48100f0 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 14:36:08 2024 -0400 Controller commit e64948bef5c3d0024ad3756a812ba980b6aa62f2 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 14:24:28 2024 -0400 ws
2024-08-14 09:30:27 -04:00
import '../../views/lcd.dart';
import '../../views/keypad.dart';
import '../../views/login.dart';
2024-08-17 16:51:47 -04:00
import '../controller/stillbox.dart';
import 'play.dart';
2024-08-10 13:27:12 -04:00
class MainRadio extends StatefulWidget {
const MainRadio({super.key, required this.title});
final String title;
@override
State<MainRadio> createState() => _MainRadioState();
}
class _MainRadioState extends State<MainRadio> {
2024-08-18 08:27:03 -04:00
final player = JustAudioDriver();
2024-08-17 16:51:47 -04:00
bool lcdState = false;
static const _lcdTimeout = 3;
static const _lcdOnColor = Colors.amber;
static const _lcdOffColor = Color.fromARGB(255, 255, 219, 110);
Color _lcdColor = _lcdOffColor;
Color _ledColor = Colors.black;
Timer? _lcdTimer;
SBCall? _call;
2024-08-18 08:41:29 -04:00
Completer _completer = Completer();
2024-08-18 09:17:10 -04:00
int queueLen = 0;
2024-08-20 09:11:21 -04:00
DateFormat timeFormat = DateFormat('HH:mm');
2024-08-17 16:51:47 -04:00
2024-10-14 11:42:48 -04:00
void _setupAudioSession() async {
final session = await AudioSession.instance;
await session.configure(AudioSessionConfiguration.music());
}
2024-08-17 16:51:47 -04:00
@override
void initState() {
super.initState();
2024-10-14 11:42:48 -04:00
_setupAudioSession();
2024-08-17 16:51:47 -04:00
final sb = Provider.of<Stillbox>(context, listen: false);
2024-10-14 11:42:48 -04:00
2024-08-18 08:27:03 -04:00
player.player.playerStateStream.listen((event) async {
2024-08-18 09:17:10 -04:00
if (event.processingState == ProcessingState.completed &&
!_completer.isCompleted) {
2024-08-18 08:41:29 -04:00
_completer.complete();
2024-08-17 16:51:47 -04:00
setState(() {
_ledColor = Colors.black;
});
}
});
2024-08-18 09:17:10 -04:00
sb.callQStream.stream.listen((ctAdd) {
setState(() {
queueLen += ctAdd;
});
});
2024-08-17 21:53:19 -04:00
_callLoop(sb);
}
void _handleSocketError(dynamic error) {
Navigator.pushReplacement(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => const Login(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return child;
},
transitionDuration: const Duration(milliseconds: 0),
),
);
}
2024-08-17 21:53:19 -04:00
void _callLoop(Stillbox sb) async {
var streamWithoutErrors =
sb.callStream.stream.handleError((error) => _handleSocketError(error));
await for (final call in streamWithoutErrors) {
2024-08-17 16:51:47 -04:00
lcdOn();
setState(() {
_call = call;
2024-08-18 09:17:10 -04:00
queueLen--;
2024-08-17 16:51:47 -04:00
});
2024-08-18 08:41:29 -04:00
_completer = Completer();
2024-08-18 09:17:10 -04:00
player.play(call.call);
2024-08-18 08:41:29 -04:00
await _completer.future;
2024-08-17 16:51:47 -04:00
lcdOff();
2024-08-17 21:53:19 -04:00
} //);
2024-08-17 16:51:47 -04:00
}
void lcdOn() {
if (_lcdTimer != null) {
_lcdTimer!.cancel();
_lcdTimer = null;
}
setState(() {
2024-08-21 09:11:27 -04:00
_ledColor = const Color.fromARGB(255, 226, 62, 255);
2024-08-17 16:51:47 -04:00
_lcdColor = _lcdOnColor;
});
}
void lcdOff() {
if (_lcdTimer != null) {
_lcdTimer!.cancel();
}
_lcdTimer = Timer(const Duration(seconds: _lcdTimeout), () {
setState(() {
_lcdColor = _lcdOffColor;
});
_lcdTimer = null;
});
}
2024-08-10 13:27:12 -04:00
@override
Widget build(BuildContext context) {
2024-08-17 16:51:47 -04:00
return SafeArea(
Something mostly working. Squashed commit of the following: commit b15263546eadbc86de233996c5c32ceb17e0a45d Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 09:29:49 2024 -0400 save bytes source class commit 3a6ac8868583a286c28f3d3de8b9a42ac52c5ba5 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 09:26:28 2024 -0400 safearea commit c411a007e62d4bb4551ce7f142ce7c3ef02485f9 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:33:11 2024 -0400 try to play commit 5a8e7c7690d803a1d676a7e4a30ef9807cd17294 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:29:53 2024 -0400 protoc commit c776d37765b522b0ac87e3b5efb5561e65a218a6 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:28:26 2024 -0400 wip commit 0d150d73d8f2631b7f6669e935ec212bbfb98ef8 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 23:07:35 2024 -0400 big huge wip commit db99eeb43ad35259d3bc998d63afd94e8bcf84b5 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 21:03:42 2024 -0400 big wip commit 5af1b90ccca175566c3bfad397dbd7b14e08cee7 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 20:04:37 2024 -0400 WIP commit 08183de44f347e2962b2a5830b920ce3bad08a7a Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 10:41:06 2024 -0400 notifier commit 5f92cf977ba657b94c623b891421169ce6d887fd Author: Daniel Ponte <amigan@gmail.com> Date: Mon Aug 12 09:13:43 2024 -0400 wip commit d6d590684d091d4746743fe8a77ee548e88a3f17 Author: Daniel Ponte <amigan@gmail.com> Date: Mon Aug 12 07:47:08 2024 -0400 fix commit 9d58f4fa7f75fccd88e8720af5e6aa1668bbb403 Author: Daniel Ponte <amigan@gmail.com> Date: Sun Aug 11 23:59:01 2024 -0400 wip commit d61ce79c295d965f457138e928b03aae4e3e6a6d Author: Daniel Ponte <amigan@gmail.com> Date: Sun Aug 11 19:23:16 2024 -0400 wip commit f4ea5916b8ca4361aaaddc4e4e1842e8328747a6 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 17:07:52 2024 -0400 macos stuff commit fe8bdc13a5ea12b10eb4110158aa7248ff851889 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 17:07:04 2024 -0400 add default case commit 9bc788035b1ba3c576a3ee1c7120259e727e24a2 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 16:38:46 2024 -0400 wip commit 8e99afeb31f7bba36264347ad11aed0ce48100f0 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 14:36:08 2024 -0400 Controller commit e64948bef5c3d0024ad3756a812ba980b6aa62f2 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 14:24:28 2024 -0400 ws
2024-08-14 09:30:27 -04:00
child: Scaffold(
body: Center(
2024-08-10 13:27:12 -04:00
child: SizedBox(
width: 500.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
2024-08-17 16:51:47 -04:00
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
const ScannerLabel('Stillbox'),
LED(_ledColor),
]),
2024-08-20 09:11:21 -04:00
LCD(_call, _lcdColor, queueLen, timeFormat),
2024-08-17 16:51:47 -04:00
const Keypad(),
2024-08-10 13:27:12 -04:00
],
)),
),
Something mostly working. Squashed commit of the following: commit b15263546eadbc86de233996c5c32ceb17e0a45d Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 09:29:49 2024 -0400 save bytes source class commit 3a6ac8868583a286c28f3d3de8b9a42ac52c5ba5 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 09:26:28 2024 -0400 safearea commit c411a007e62d4bb4551ce7f142ce7c3ef02485f9 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:33:11 2024 -0400 try to play commit 5a8e7c7690d803a1d676a7e4a30ef9807cd17294 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:29:53 2024 -0400 protoc commit c776d37765b522b0ac87e3b5efb5561e65a218a6 Author: Daniel Ponte <amigan@gmail.com> Date: Wed Aug 14 08:28:26 2024 -0400 wip commit 0d150d73d8f2631b7f6669e935ec212bbfb98ef8 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 23:07:35 2024 -0400 big huge wip commit db99eeb43ad35259d3bc998d63afd94e8bcf84b5 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 21:03:42 2024 -0400 big wip commit 5af1b90ccca175566c3bfad397dbd7b14e08cee7 Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 20:04:37 2024 -0400 WIP commit 08183de44f347e2962b2a5830b920ce3bad08a7a Author: Daniel Ponte <amigan@gmail.com> Date: Tue Aug 13 10:41:06 2024 -0400 notifier commit 5f92cf977ba657b94c623b891421169ce6d887fd Author: Daniel Ponte <amigan@gmail.com> Date: Mon Aug 12 09:13:43 2024 -0400 wip commit d6d590684d091d4746743fe8a77ee548e88a3f17 Author: Daniel Ponte <amigan@gmail.com> Date: Mon Aug 12 07:47:08 2024 -0400 fix commit 9d58f4fa7f75fccd88e8720af5e6aa1668bbb403 Author: Daniel Ponte <amigan@gmail.com> Date: Sun Aug 11 23:59:01 2024 -0400 wip commit d61ce79c295d965f457138e928b03aae4e3e6a6d Author: Daniel Ponte <amigan@gmail.com> Date: Sun Aug 11 19:23:16 2024 -0400 wip commit f4ea5916b8ca4361aaaddc4e4e1842e8328747a6 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 17:07:52 2024 -0400 macos stuff commit fe8bdc13a5ea12b10eb4110158aa7248ff851889 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 17:07:04 2024 -0400 add default case commit 9bc788035b1ba3c576a3ee1c7120259e727e24a2 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 16:38:46 2024 -0400 wip commit 8e99afeb31f7bba36264347ad11aed0ce48100f0 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 14:36:08 2024 -0400 Controller commit e64948bef5c3d0024ad3756a812ba980b6aa62f2 Author: Daniel Ponte <amigan@gmail.com> Date: Sat Aug 10 14:24:28 2024 -0400 ws
2024-08-14 09:30:27 -04:00
));
2024-08-10 13:27:12 -04:00
}
2024-08-17 16:51:47 -04:00
Widget lcdContents() {
return Consumer<Stillbox>(builder: (context, sb, child) {
return Container();
});
}
2024-08-10 13:27:12 -04:00
}