nice
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:bus_infotainment/backend/live_information.dart';
|
||||
import 'package:bus_infotainment/tfl_datasets.dart';
|
||||
import 'package:bus_infotainment/utils/audio%20wrapper.dart';
|
||||
import 'package:bus_infotainment/utils/delegates.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'info_module.dart';
|
||||
|
||||
@@ -19,6 +21,28 @@ class AnnouncementModule extends InfoModule {
|
||||
refreshTimer();
|
||||
}
|
||||
|
||||
// Files
|
||||
String _bundleLocation = "assets/ibus_recordings.zip";
|
||||
Uint8List? _bundleBytes;
|
||||
void setBundleBytes(Uint8List bytes) {
|
||||
_bundleBytes = bytes;
|
||||
}
|
||||
Future<Uint8List> getBundleBytes() async {
|
||||
|
||||
if (_bundleBytes != null) {
|
||||
return _bundleBytes!;
|
||||
} else {
|
||||
|
||||
if (kIsWeb) {
|
||||
throw Exception("Cannot load bundle bytes on web");
|
||||
}
|
||||
|
||||
final bytes = await rootBundle.load(_bundleLocation);
|
||||
return bytes.buffer.asUint8List();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Queue
|
||||
List<AnnouncementQueueEntry> queue = [];
|
||||
AnnouncementQueueEntry? currentAnnouncement;
|
||||
@@ -63,23 +87,34 @@ class AnnouncementModule extends InfoModule {
|
||||
onAnnouncement.trigger(currentAnnouncement!);
|
||||
|
||||
if (currentAnnouncement!.audioSources.isNotEmpty) {
|
||||
try {
|
||||
|
||||
audioPlayer.loadSource(AudioWrapperAssetSource("assets/audio/5-seconds-of-silence.mp3"));
|
||||
audioPlayer.play();
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
audioPlayer.stop();
|
||||
|
||||
// try {
|
||||
for (AudioWrapperSource source in currentAnnouncement!.audioSources) {
|
||||
try {
|
||||
await audioPlayer.loadSource(source);
|
||||
|
||||
await audioPlayer.loadSource(source);
|
||||
|
||||
Duration? duration = await audioPlayer.play();
|
||||
await Future.delayed(duration!);
|
||||
if (currentAnnouncement?.audioSources.last != source) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
Duration? duration = await audioPlayer.play();
|
||||
await Future.delayed(duration!);
|
||||
if (currentAnnouncement?.audioSources.last != source) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
} catch (e) {
|
||||
// Do nothing
|
||||
// print("Error playing announcement: $e on ${currentAnnouncement?.displayText}");
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
audioPlayer.stop();
|
||||
// audioPlayer.stop();
|
||||
|
||||
} catch (e) {
|
||||
// Do nothing
|
||||
print("Error playing announcement: $e");
|
||||
}
|
||||
// } catch (e) {
|
||||
// // Do nothing
|
||||
// print("Error playing announcement: $e on ${currentAnnouncement?.displayTex}");
|
||||
// }
|
||||
} else {
|
||||
if (queue.isNotEmpty) {
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
@@ -153,7 +188,7 @@ class AnnouncementModule extends InfoModule {
|
||||
}
|
||||
|
||||
// Cache the announcements
|
||||
await announcementCache.loadAnnouncements(audioNames);
|
||||
await announcementCache.loadAnnouncementsFromBytes((await getBundleBytes())!, audioNames);
|
||||
|
||||
List<AudioWrapperSource> sources = [];
|
||||
|
||||
@@ -227,7 +262,7 @@ class AnnouncementModule extends InfoModule {
|
||||
|
||||
String audioRoute = "R_${routeVariant.busRoute.routeNumber}_001.mp3";
|
||||
|
||||
await announcementCache.loadAnnouncements([audioRoute, "R_RAIL_REPLACEMENT_SERVICE_001.mp3"]);
|
||||
await announcementCache.loadAnnouncementsFromBytes(await getBundleBytes(), [audioRoute, "R_RAIL_REPLACEMENT_SERVICE_001.mp3"]);
|
||||
|
||||
AudioWrapperSource sourceRoute = !routeNumber.toLowerCase().startsWith("ul") ?
|
||||
AudioWrapperByteSource(announcementCache[audioRoute]!) :
|
||||
|
||||
Reference in New Issue
Block a user