/
audio.js
34 lines (30 loc) · 880 Bytes
/
audio.js
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
/* @flow */
/**
* Simple wrapper on react-native-sound that exposes the sound effects used in the game.
*/
import ReactNativeSound from 'react-native-sound';
const initializeSound = (name: string) => {
return new ReactNativeSound(name, ReactNativeSound.MAIN_BUNDLE, err => {
if (err) {
console.warn('failed to load the sound', err);
}
});
};
const playSound = sound => {
sound.getCurrentTime(currentTime => {
if (currentTime === 0) {
sound.play();
} else {
sound.stop();
sound.play();
}
});
};
const successSound = initializeSound('success.wav');
const buttonSound = initializeSound('button.wav');
const failureSound = initializeSound('failure.wav');
export default {
playSuccessSound: () => playSound(successSound),
playButtonSound: () => playSound(buttonSound),
playFailureSound: () => playSound(failureSound),
};