@@ -34,44 +34,57 @@ With this library, unleash creativity by generating captivating audio waveforms
3434## Usage 🎶
3535
3636``` js
37- import React , { useState } from ' react' ;
38-
39- import { Alert , ScrollView , StyleSheet , View } from ' react-native' ;
40- import { analyzeAudio , scale , sample , AmplitudeData } from ' react-native-audio-analyzer' ;
37+ import { analyzeAudio , scale , sample } from ' react-native-audio-analyzer' ;
38+ import ReactNativeBlobUtil from ' react-native-blob-util' ;
4139
4240export default function App () {
43- const [result , setResult ] = useState< AmplitudeData[]> ([]);
44-
45- useEffect (() => {
46- // Local location on disk. !Important!: You must take care of downloading the file and give the application reading permissions
47- analyzeAudio (' <uri to audio file>' )
48- .then (res => setResult (res))
49- .catch (err => {
50- // handle error
51- });
41+ const [result , setResult ] = useState ([]);
42+
43+ const start = useCallback (async () => {
44+ try {
45+ const response = await ReactNativeBlobUtil .config ({
46+ fileCache: true ,
47+ }).fetch (
48+ ' GET' ,
49+ ' https://file-examples.com/storage/fe61380d0265a2c7a970ef9/2017/11/file_example_WAV_10MG.wav' ,
50+ {}
51+ );
52+ const path = response .path ();
53+ const data = await analyzeAudio (path);
54+ setResult (data);
55+ } catch (error) {
56+ console .log (error);
57+ }
5258 }, []);
5359
5460 return (
5561 < View style= {styles .container }>
62+ < Button title= " Start" onPress= {start} / >
5663 < ScrollView horizontal style= {styles .scroll }>
5764 < View style= {styles .row }>
58- {result .length > 0 && scale (result .map (_ => _ .amplitude )).map ((value , index ) => (
59- < View
60- key= {index}
61- style= {[styles .item , { height: value * 100 }]}
62- / >
63- ))}
65+ {result .length > 0 &&
66+ scale (result .map ((_ ) => _ .amplitude )).map ((value , index ) => (
67+ < View
68+ key= {index}
69+ style= {[styles .item , { height: value * 100 }]}
70+ / >
71+ ))}
6472 < / View>
6573 < / ScrollView>
6674 < ScrollView horizontal style= {styles .scroll }>
6775 < View style= {styles .row }>
68- {result .length > 0 && scale (
69- sample (result .map (_ => _ .amplitude ), 20 )).map ((value , index ) => (
70- < View
71- key= {index}
72- style= {[styles .item , { height: value * 100 }]}
73- / >
74- ))}
76+ {result .length > 0 &&
77+ scale (
78+ sample (
79+ result .map ((_ ) => _ .amplitude ),
80+ 20
81+ )
82+ ).map ((value , index ) => (
83+ < View
84+ key= {index}
85+ style= {[styles .item , { height: value * 100 }]}
86+ / >
87+ ))}
7588 < / View>
7689 < / ScrollView>
7790 < / View>
@@ -100,6 +113,7 @@ const styles = StyleSheet.create({
100113 },
101114});
102115
116+
103117```
104118
105119## Contributing 🤝
0 commit comments