forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsounds.ts
34 lines (30 loc) · 843 Bytes
/
sounds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import mapValues from 'lodash/mapValues'
import { Player } from '@react-native-community/audio-toolkit'
const soundsMap = {
messageReceived: 'Berty_Notif_Message.mp3',
messageSent: 'Notif_Berty15message_envoye.mp3',
contactRequestSent: 'Notif_Berty02.mp3',
contactRequestReceived: 'Notif_Berty04.mp3',
contactRequestAccepted: 'Notif_Berty14.mp3',
groupCreated: 'Notif_Berty13.mp3',
}
export type SoundKey = keyof typeof soundsMap
const preloadedSounds = mapValues(soundsMap, (fileName) => {
const p = new Player(fileName, { autoDestroy: false, mixWithOthers: true })
p.prepare()
return p
})
export const playSound = (name: SoundKey) => {
const p = preloadedSounds[name]
if (!p) {
console.warn(`Tried to play unknown sound "${name}"`)
return
}
if (!p.isPlaying) {
p.play()
return
}
p.seek(0, () => {
p.play()
})
}