-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
52 lines (45 loc) · 1.17 KB
/
Copy pathApp.js
File metadata and controls
52 lines (45 loc) · 1.17 KB
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
import React from 'react';
import { SafeAreaView, View, Text, Button, } from 'react-native';
import Loudness from 'react-native-loudness';
export default class AppView extends React.Component {
constructor(){
super();
this.state = {
loudness: 0,
isRecording: false,
}
this.loudnessGetter = null
}
onPress = () => {
if (!this.state.isRecording){
// Loudness.start();
Loudness.start('test');
this.loudnessGetter = setInterval(() => {
Loudness.getLoudness((l) => {
if (!isFinite(l)) return;
this.setState({loudness: l});
});
}, 100);
this.setState({isRecording: true});
} else {
Loudness.stop();
clearInterval(this.loudnessGetter);
this.loudnessGetter = null;
this.setState({isRecording: false,loudness: 0});
}
}
render(){
return(
<View style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<Text>{'Loudness: '+ this.state.loudness.toFixed(2)}</Text>
<Button
title = {this.state.isRecording?'Stop':'Start'}
onPress = {this.onPress}/>
</View>
);
}
}