-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
99 lines (93 loc) · 2.44 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { useState } from 'react';
import { Text, View, TouchableOpacity, StyleSheet, Animated } from 'react-native';
import { Audio } from 'expo-av';
import { getAudioData, polarPath } from "./waveform-path.js";
import { Svg, Path } from 'react-native-svg';
const App = () => {
const [audioSvg, setAudioSvg] = useState();
const audioSound = require('./assets/hello_world.ogg');
// Play a sound //
const playSound = async () => {
try {
const soundObject = new Audio.Sound();
await soundObject.loadAsync(audioSound);
await soundObject.playAsync();
} catch (error) {
console.log('Error playing sound:', error);
}
AudioPath(audioSound);
};
const AudioPath = async(file) => {
try {
const audioData = await getAudioData(file);
const pathLogo = polarPath(audioData,{
samples: 100,
type: 'steps',
left: 200,
top: 200,
distance: 100,
length: 100,
animation: true
});
setAudioSvg({ d: pathLogo });
} catch (error) {
console.log('Error retrieving audio data:', error);
}
AudioPath(audioSound);
};
// Render UI //
return (
<View style={styles.main}>
<View style={styles.topView}>
<Svg width="100%" height="100%">
<Path fill="white" stroke="black" {...audioSvg} />
</Svg>
</View>
<View style={styles.bottomView}>
<TouchableOpacity onPress={playSound}>
<View style={styles.buttonContainer}>
<Text style={styles.buttonText}>Play</Text>
</View>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
main: {
flex: 1,
padding: 18,
paddingTop: 32
},
topView: {
flex: 2,
width: '100%'
},
waveform: {
flexDirection: 'row',
overflow: 'hidden',
},
waveformPoint: {
width: 2,
backgroundColor: 'blue', // Adjust the color as per your preference
},
bottomView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
buttonContainer: {
justifyContent: 'center',
alignItems: 'center',
width: 150,
height: 50,
backgroundColor: 'orange',
borderRadius: 14
},
buttonText: {
fontSize: 18,
fontWeight: 600,
color: 'white'
}
})
export default App;