-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added functions to index and added working example
- Loading branch information
1 parent
5a10a0e
commit 94223d1
Showing
5 changed files
with
196 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.liveaudiovisualizer"> | ||
<uses-permission android:name="android.permission.RECORD_AUDIO" /> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,82 @@ | ||
import * as React from 'react'; | ||
|
||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { multiply } from 'react-native-live-audio-visualizer'; | ||
import { DeviceEventEmitter, StyleSheet, View } from 'react-native'; | ||
import { | ||
RequestAudioPermission, | ||
startAudioListening, | ||
stopAudioListening, | ||
} from 'react-native-live-audio-visualizer'; | ||
|
||
export default function App() { | ||
const [result, setResult] = React.useState<number | undefined>(); | ||
const [result, setResult] = React.useState<number[]>([]); | ||
|
||
React.useEffect(() => { | ||
multiply(3, 7).then(setResult); | ||
RequestAudioPermission( | ||
'This app needs audio permission', | ||
'Permission for audio', | ||
'OK' | ||
); | ||
|
||
startAudioListening().then(() => { | ||
console.log('Audio listening started'); | ||
}); | ||
|
||
DeviceEventEmitter.addListener('VisualizationChanged', (data) => { | ||
console.log('Event received:', data); | ||
|
||
setResult(data); | ||
}); | ||
|
||
return () => { | ||
stopAudioListening().then(() => { | ||
console.log('Audio listening stopped'); | ||
}); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Result: {result}</Text> | ||
<View style={styles.waveContainer}> | ||
{result.map((wave, index) => ( | ||
<View | ||
key={index} | ||
style={[ | ||
styles.waveItem, | ||
{ | ||
height: wave * 100, | ||
}, | ||
]} | ||
/> | ||
))} | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
backgroundColor: 'black', | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
waveContainer: { | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
width: '100%', | ||
flexDirection: 'row', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
}, | ||
waveItem: { | ||
width: 12, | ||
backgroundColor: '#B692F6', | ||
marginHorizontal: 1, | ||
borderRadius: 4, | ||
minHeight: 10, | ||
marginRight: 8, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters