2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 04:05:28 +00:00

Refactor audio file player

- Do not play if there is no context available (e.g. unit testing)
This commit is contained in:
Oliver Walters
2022-05-22 08:23:20 +10:00
parent e424a3cf7b
commit f13b04d029
7 changed files with 94 additions and 50 deletions

View File

@ -8,8 +8,7 @@
*/
import "package:audioplayers/audioplayers.dart";
import "package:inventree/preferences.dart";
import "package:one_context/one_context.dart";
String simpleNumberString(double number) {
// Ref: https://stackoverflow.com/questions/55152175/how-to-remove-trailing-zeros-using-dart
@ -17,22 +16,19 @@ String simpleNumberString(double number) {
return number.toStringAsFixed(number.truncateToDouble() == number ? 0 : 1);
}
Future<void> successTone() async {
/*
* Play an audio file from the requested path.
*
* Note: If OneContext module fails the 'hasConext' check,
* we will not attempt to play the sound
*/
Future<void> playAudioFile(String path) async {
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
if (en) {
final player = AudioCache();
player.play("sounds/barcode_scan.mp3");
if (!OneContext.hasContext) {
return;
}
final player = AudioCache();
player.play(path);
}
Future <void> failureTone() async {
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
if (en) {
final player = AudioCache();
player.play("sounds/barcode_error.mp3");
}
}