mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 03:26:24 +00:00
Refactor audio file player
- Do not play if there is no context available (e.g. unit testing)
This commit is contained in:
parent
e424a3cf7b
commit
f13b04d029
7 changed files with 94 additions and 50 deletions
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue