-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
62 lines (58 loc) · 1.5 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
import React, {useState} from 'react';
import {Text, View, TouchableOpacity} from 'react-native';
import RNSoundLevel from 'react-native-sound-level';
import SoundPlayer from 'react-native-sound-player';
export default App => {
const [sound, setSound] = useState(false);
function soundLevel() {
if (!sound) {
RNSoundLevel.start();
setSound(true);
RNSoundLevel.onNewFrame = data => {
console.log('Sound level info', data);
};
} else {
setSound(false);
RNSoundLevel.stop();
}
}
function playSound() {
try {
SoundPlayer.playSoundFile('wakeup', 'mp3');
} catch (e) {
console.log(`cannot play the sound file`, e);
}
}
return (
<View>
<TouchableOpacity
style={{
backgroundColor: '#9dbad1',
borderRadius: 40,
marginTop: 100,
marginLeft: 50,
width: 300,
height: 100,
alignItems: 'center',
justifyContent: 'center',
}}
onPress={soundLevel}>
<Text style={{fontSize: 20}}>SoundLevel</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
backgroundColor: '#9dbad1',
borderRadius: 40,
marginTop: 200,
marginLeft: 50,
width: 300,
height: 100,
alignItems: 'center',
justifyContent: 'center',
}}
onPress={playSound}>
<Text style={{fontSize: 20}}>PlaySound</Text>
</TouchableOpacity>
</View>
);
};