-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
71 lines (63 loc) · 1.7 KB
/
App.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { StatusBar } from "expo-status-bar";
import React from "react";
import { Button, StyleSheet, Text, TouchableOpacity, View } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
// import fart1 from "./assets/soundfiles/555418__kuchtaa__wet-fart.mp3";
import { Audio } from "expo-av";
export default function App() {
const [sound, setSound] = React.useState();
async function playSound() {
console.log("Loading Sound");
//todo: select a random file from folder ./assets/soundfiles
const { sound } = await Audio.Sound.createAsync(
require("./assets/soundfiles/523467__tv_ling__perfect-fart.mp3")
);
setSound(sound);
console.log("Playing Sound");
await sound.playAsync();
}
React.useEffect(() => {
return sound
? () => {
console.log("Unloading Sound");
sound.unloadAsync();
}
: undefined;
}, [sound]);
return (
<SafeAreaProvider>
<View style={styles.container}>
<Text>ALO!</Text>
<TouchableOpacity onPress={playSound}>
<View style={styles.button}>
<Text style={styles.buttonText}>Puxa meu dedo!</Text>
</View>
</TouchableOpacity>
</View>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#222",
alignItems: "center",
justifyContent: "center",
},
button: {
width: 200,
height: 200,
borderRadius: 200,
color: "red",
backgroundColor: "blue",
display: "flex",
alignItems: "center",
justifyContent: "center",
},
buttonText: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
fontFamily: "monospace",
},
});