expo-audio 0.3.3 → 0.3.4
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.
- package/CHANGELOG.md +6 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/audio/AudioModule.kt +1 -1
- package/android/src/main/java/expo/modules/audio/AudioRecorder.kt +27 -9
- package/android/src/main/java/expo/modules/audio/AudioUtils.kt +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 0.3.4 — 2025-01-19
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- [Android] Add checks to methods that will throw without permissions being granted. ([#33986](https://github.com/expo/expo/pull/33986) by [@alanjhughes](https://github.com/alanjhughes))
|
|
18
|
+
|
|
13
19
|
## 0.3.3 — 2025-01-10
|
|
14
20
|
|
|
15
21
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'expo.modules.audio'
|
|
4
|
-
version = '0.3.
|
|
4
|
+
version = '0.3.4'
|
|
5
5
|
|
|
6
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
7
|
apply from: expoModulesCorePlugin
|
|
@@ -14,7 +14,7 @@ android {
|
|
|
14
14
|
namespace "expo.modules.audio"
|
|
15
15
|
defaultConfig {
|
|
16
16
|
versionCode 1
|
|
17
|
-
versionName "0.3.
|
|
17
|
+
versionName "0.3.4"
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
compileOptions {
|
|
@@ -325,6 +325,7 @@ class AudioModule : Module() {
|
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
AsyncFunction("prepareToRecordAsync") { ref: AudioRecorder, options: RecordingOptions? ->
|
|
328
|
+
checkRecordingPermission()
|
|
328
329
|
ref.prepareRecording(options)
|
|
329
330
|
}
|
|
330
331
|
|
|
@@ -344,7 +345,6 @@ class AudioModule : Module() {
|
|
|
344
345
|
}
|
|
345
346
|
|
|
346
347
|
Function("getStatus") { ref: AudioRecorder ->
|
|
347
|
-
checkRecordingPermission()
|
|
348
348
|
ref.getAudioRecorderStatus()
|
|
349
349
|
}
|
|
350
350
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
package expo.modules.audio
|
|
2
2
|
|
|
3
|
+
import android.Manifest
|
|
3
4
|
import android.content.Context
|
|
5
|
+
import android.content.pm.PackageManager
|
|
4
6
|
import android.media.AudioDeviceInfo
|
|
5
7
|
import android.media.AudioManager
|
|
6
8
|
import android.media.MediaRecorder
|
|
@@ -11,6 +13,7 @@ import android.net.Uri
|
|
|
11
13
|
import android.os.Build
|
|
12
14
|
import android.os.Bundle
|
|
13
15
|
import android.os.SystemClock
|
|
16
|
+
import androidx.core.content.ContextCompat
|
|
14
17
|
import expo.modules.kotlin.AppContext
|
|
15
18
|
import expo.modules.kotlin.sharedobjects.SharedObject
|
|
16
19
|
import java.io.File
|
|
@@ -33,7 +36,7 @@ class AudioRecorder(
|
|
|
33
36
|
private var isPrepared = false
|
|
34
37
|
private var shouldCreateRecorder = false
|
|
35
38
|
|
|
36
|
-
var recorder = createRecorder(options)
|
|
39
|
+
private var recorder = createRecorder(options)
|
|
37
40
|
val id = UUID.randomUUID().toString()
|
|
38
41
|
var uri: String? = null
|
|
39
42
|
var uptime = 0L
|
|
@@ -106,8 +109,11 @@ class AudioRecorder(
|
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
private fun setRecordingOptions(recorder: MediaRecorder, options: RecordingOptions) {
|
|
112
|
+
if (!hasRecordingPermissions()) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
109
115
|
with(recorder) {
|
|
110
|
-
setAudioSource(MediaRecorder.AudioSource.
|
|
116
|
+
setAudioSource(MediaRecorder.AudioSource.MIC)
|
|
111
117
|
if (options.outputFormat != null) {
|
|
112
118
|
setOutputFormat(options.outputFormat.toMediaOutputFormat())
|
|
113
119
|
} else {
|
|
@@ -153,14 +159,23 @@ class AudioRecorder(
|
|
|
153
159
|
recorder.release()
|
|
154
160
|
}
|
|
155
161
|
|
|
156
|
-
fun getAudioRecorderStatus() =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
+
fun getAudioRecorderStatus() = if (hasRecordingPermissions()) {
|
|
163
|
+
Bundle().apply {
|
|
164
|
+
putBoolean("canRecord", isPrepared)
|
|
165
|
+
putBoolean("isRecording", isRecording)
|
|
166
|
+
putLong("durationMillis", getAudioRecorderDurationMillis())
|
|
167
|
+
if (meteringEnabled) {
|
|
168
|
+
putInt("metering", getAudioRecorderLevels())
|
|
169
|
+
}
|
|
170
|
+
putString("url", uri)
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
Bundle().apply {
|
|
174
|
+
putBoolean("canRecord", false)
|
|
175
|
+
putBoolean("isRecording", false)
|
|
176
|
+
putLong("durationMillis", 0)
|
|
177
|
+
putString("url", null)
|
|
162
178
|
}
|
|
163
|
-
putString("url", uri)
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
private fun getAudioRecorderDurationMillis(): Long {
|
|
@@ -246,6 +261,9 @@ class AudioRecorder(
|
|
|
246
261
|
return getMapFromDeviceInfo(deviceInfo)
|
|
247
262
|
}
|
|
248
263
|
|
|
264
|
+
private fun hasRecordingPermissions() =
|
|
265
|
+
ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
|
|
266
|
+
|
|
249
267
|
fun getAvailableInputs(audioManager: AudioManager) =
|
|
250
268
|
audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS).mapNotNull { deviceInfo ->
|
|
251
269
|
val type = deviceInfo.type
|
|
@@ -6,7 +6,7 @@ import java.io.File
|
|
|
6
6
|
import java.io.IOException
|
|
7
7
|
|
|
8
8
|
fun ensureDirExists(dir: File): File {
|
|
9
|
-
if (!(dir.isDirectory
|
|
9
|
+
if (!(dir.isDirectory || dir.mkdirs())) {
|
|
10
10
|
throw IOException("Couldn't create directory '$dir'")
|
|
11
11
|
}
|
|
12
12
|
return dir
|
|
@@ -22,7 +22,7 @@ fun getMapFromDeviceInfo(deviceInfo: AudioDeviceInfo): Bundle {
|
|
|
22
22
|
AudioDeviceInfo.TYPE_WIRED_HEADSET -> "MicrophoneWired"
|
|
23
23
|
else -> "Unknown device type"
|
|
24
24
|
}
|
|
25
|
-
map.putString("name", deviceInfo.
|
|
25
|
+
map.putString("name", deviceInfo.productName.toString())
|
|
26
26
|
map.putString("type", type)
|
|
27
27
|
map.putString("uid", deviceInfo.id.toString())
|
|
28
28
|
return map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-audio",
|
|
3
3
|
"title": "Expo Audio",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.4",
|
|
5
5
|
"description": "A cross-platform audio library for React Native and Expo apps.",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"types": "build/index.d.ts",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"react": "*",
|
|
41
41
|
"react-native": "*"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "0a0c6d35a691fc59c0d94675d159ac9e3dfd6f26"
|
|
44
44
|
}
|