react-native-simple-note-pitch-detector 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package expo.modules.simplenotepitchdetector
|
|
2
2
|
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.content.pm.PackageManager
|
|
5
|
+
import androidx.core.app.ActivityCompat
|
|
3
6
|
import expo.modules.kotlin.modules.Module
|
|
4
7
|
import expo.modules.kotlin.modules.ModuleDefinition
|
|
5
8
|
import expo.modules.simplepitchdetector.PitchAnalyzer
|
|
@@ -7,6 +10,7 @@ import androidx.core.os.bundleOf
|
|
|
7
10
|
|
|
8
11
|
class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
9
12
|
|
|
13
|
+
private var permissions = arrayOf(Manifest.permission.RECORD_AUDIO)
|
|
10
14
|
|
|
11
15
|
override fun definition() = ModuleDefinition {
|
|
12
16
|
Name("ReactNativeSimpleNotePitchDetector")
|
|
@@ -14,13 +18,23 @@ class ReactNativeSimpleNotePitchDetectorModule : Module() {
|
|
|
14
18
|
Events("onChange")
|
|
15
19
|
|
|
16
20
|
Function("hello") {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
val context = appContext.reactContext!!
|
|
23
|
+
|
|
24
|
+
var activity = appContext.currentActivity!!
|
|
25
|
+
|
|
26
|
+
var permissionsGranted = ActivityCompat.checkSelfPermission(context, permissions[0]) == PackageManager.PERMISSION_GRANTED
|
|
27
|
+
if (!permissionsGranted) {
|
|
28
|
+
ActivityCompat.requestPermissions(activity, permissions, 200)
|
|
29
|
+
} else {
|
|
30
|
+
val pitchAnalyzer = PitchAnalyzer {
|
|
31
|
+
this@ReactNativeSimpleNotePitchDetectorModule.sendEvent(
|
|
32
|
+
"onChange",
|
|
33
|
+
bundleOf("tone" to it)
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
pitchAnalyzer.start()
|
|
22
37
|
}
|
|
23
|
-
pitchAnalyzer.start()
|
|
24
38
|
}
|
|
25
39
|
}
|
|
26
40
|
}
|