summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-09-13 12:58:24 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-09-13 12:58:24 +0200
commit59d4e24ec12fb4ec642fb70317c85b98056c2232 (patch)
tree982c714c7e909dc40e95dd7143f057992fac2e63
parent0d468cc8c158f884b7f63a9bdcf351726e934171 (diff)
Reproduce an alert audio from remote file
-rw-r--r--app/(tabs)/index.tsx28
1 files changed, 22 insertions, 6 deletions
diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx
index d45f1ac..4168c8f 100644
--- a/app/(tabs)/index.tsx
+++ b/app/(tabs)/index.tsx
@@ -147,8 +147,23 @@ export default function HomeScreen() {
const [sound, setSound] = useState<Audio.Sound | null>(null);
- async function playSound() {
- const { sound } = await Audio.Sound.createAsync(require('../../assets/sounds/occhio.mp3'));
+ async function playSound(alert: string, level: string) {
+ let levelDigit: string;
+ switch (level) {
+ case "ONE":
+ levelDigit = "1";
+ break;
+ case "TWO":
+ levelDigit = "2";
+ break;
+ case "THREE":
+ levelDigit = "3";
+ break;
+ default: return;
+ }
+ const { sound } = await Audio.Sound.createAsync({
+ uri: `${process.env.EXPO_PUBLIC_API_URL}/assets/sounds/alert-${alert}-text-${levelDigit}.mp3`,
+ });
setSound(sound);
await sound.playAsync();
}
@@ -378,7 +393,7 @@ export default function HomeScreen() {
"Content-Type": "application/json",
},
body: JSON.stringify({
- query: `{ notifications(seen: false) { id, createdAt, level, alert { text1 text2 text3 } position { movingActivity } } }`,
+ query: `{ notifications(seen: false) { id, createdAt, level, alert { id, text1 text2 text3 } position { movingActivity } } }`,
}),
},
);
@@ -386,9 +401,10 @@ export default function HomeScreen() {
const data = await response.json();
if (data.data && data.data.notifications && data.data.notifications.length) {
- setNotification(data.data.notifications[0]);
- if (data.data.notifications[0].position.movingActivity == "IN_VEHICLE") {
- playSound();
+ const n = data.data.notifications[0];
+ setNotification(notification);
+ if (n.position.movingActivity == "IN_VEHICLE") {
+ playSound(n.alert.id, n.level);
}
} else {
setNotification(null);