react-native-audio-api 0.6.1-rc.9 → 0.6.2-rc.0
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/android/src/main/cpp/audioapi/android/core/AudioDecoder.cpp +23 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +6 -16
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +7 -7
- package/android/src/main/java/com/swmansion/audioapi/system/PermissionRequestListener.kt +33 -0
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +31 -3
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +11 -0
- package/common/cpp/audioapi/core/BaseAudioContext.h +1 -0
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +1 -1
- package/common/cpp/audioapi/core/utils/AudioDecoder.h +1 -0
- package/common/cpp/audioapi/libs/base64/base64.h +320 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +2 -4
- package/ios/audioapi/ios/core/AudioDecoder.mm +23 -0
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +1 -1
- package/ios/audioapi/ios/system/AudioEngine.h +2 -4
- package/ios/audioapi/ios/system/AudioEngine.mm +25 -4
- package/ios/audioapi/ios/system/AudioSessionManager.h +3 -2
- package/ios/audioapi/ios/system/AudioSessionManager.mm +55 -4
- package/lib/commonjs/core/BaseAudioContext.js +8 -2
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/plugin/withAudioAPI.js +4 -4
- package/lib/commonjs/plugin/withAudioAPI.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +8 -2
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/plugin/withAudioAPI.js +4 -4
- package/lib/module/plugin/withAudioAPI.js.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +1 -0
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/plugin/withAudioAPI.d.ts +1 -1
- package/lib/typescript/plugin/withAudioAPI.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/BaseAudioContext.ts +10 -2
- package/src/interfaces.ts +1 -0
- package/src/plugin/withAudioAPI.ts +7 -9
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#include <audioapi/core/utils/AudioDecoder.h>
|
|
2
|
+
#include <audioapi/dsp/VectorMath.h>
|
|
3
|
+
#include <audioapi/libs/base64/base64.h>
|
|
2
4
|
#include <audioapi/utils/AudioArray.h>
|
|
3
5
|
#include <audioapi/utils/AudioBus.h>
|
|
4
6
|
|
|
@@ -110,4 +112,25 @@ std::shared_ptr<AudioBus> AudioDecoder::decodeWithMemoryBlock(
|
|
|
110
112
|
return audioBus;
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
std::shared_ptr<AudioBus> AudioDecoder::decodeWithPCMInBase64(
|
|
116
|
+
const std::string &data) const {
|
|
117
|
+
auto decodedData = base64_decode(data, false);
|
|
118
|
+
|
|
119
|
+
const auto uint8Data = reinterpret_cast<uint8_t *>(decodedData.data());
|
|
120
|
+
size_t frameCount = decodedData.size() / 2;
|
|
121
|
+
|
|
122
|
+
auto audioBus = std::make_shared<AudioBus>(frameCount, 1, sampleRate_);
|
|
123
|
+
auto channelData = audioBus->getChannel(0)->getData();
|
|
124
|
+
|
|
125
|
+
for (size_t i = 0; i < frameCount; ++i) {
|
|
126
|
+
auto sample =
|
|
127
|
+
static_cast<int16_t>((uint8Data[i * 2 + 1] << 8) | uint8Data[i * 2]);
|
|
128
|
+
channelData[i] = static_cast<float>(sample);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
dsp::multiplyByScalar(channelData, 1.0f / 32768.0f, channelData, frameCount);
|
|
132
|
+
|
|
133
|
+
return audioBus;
|
|
134
|
+
}
|
|
135
|
+
|
|
113
136
|
} // namespace audioapi
|
|
@@ -9,6 +9,7 @@ import com.facebook.react.common.annotations.FrameworkAPI
|
|
|
9
9
|
import com.facebook.react.module.annotations.ReactModule
|
|
10
10
|
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
11
11
|
import com.swmansion.audioapi.system.MediaSessionManager
|
|
12
|
+
import com.swmansion.audioapi.system.PermissionRequestListener
|
|
12
13
|
import java.lang.ref.WeakReference
|
|
13
14
|
|
|
14
15
|
@OptIn(FrameworkAPI::class)
|
|
@@ -53,10 +54,8 @@ class AudioAPIModule(
|
|
|
53
54
|
return true
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
@Synchronized
|
|
57
57
|
override fun getDevicePreferredSampleRate(): Double = MediaSessionManager.getDevicePreferredSampleRate()
|
|
58
58
|
|
|
59
|
-
@Synchronized
|
|
60
59
|
override fun setAudioSessionActivity(
|
|
61
60
|
enabled: Boolean,
|
|
62
61
|
promise: Promise?,
|
|
@@ -64,7 +63,6 @@ class AudioAPIModule(
|
|
|
64
63
|
// noting to do here
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
@Synchronized
|
|
68
66
|
override fun setAudioSessionOptions(
|
|
69
67
|
category: String?,
|
|
70
68
|
mode: String?,
|
|
@@ -73,17 +71,14 @@ class AudioAPIModule(
|
|
|
73
71
|
// noting to do here
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
@Synchronized
|
|
77
74
|
override fun setLockScreenInfo(info: ReadableMap?) {
|
|
78
75
|
MediaSessionManager.setLockScreenInfo(info)
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
@Synchronized
|
|
82
78
|
override fun resetLockScreenInfo() {
|
|
83
79
|
MediaSessionManager.resetLockScreenInfo()
|
|
84
80
|
}
|
|
85
81
|
|
|
86
|
-
@Synchronized
|
|
87
82
|
override fun enableRemoteCommand(
|
|
88
83
|
name: String?,
|
|
89
84
|
enabled: Boolean,
|
|
@@ -91,25 +86,20 @@ class AudioAPIModule(
|
|
|
91
86
|
MediaSessionManager.enableRemoteCommand(name!!, enabled)
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
@Synchronized
|
|
95
89
|
override fun observeAudioInterruptions(enabled: Boolean) {
|
|
96
90
|
MediaSessionManager.observeAudioInterruptions(enabled)
|
|
97
91
|
}
|
|
98
92
|
|
|
99
|
-
@Synchronized
|
|
100
93
|
override fun observeVolumeChanges(enabled: Boolean) {
|
|
101
94
|
MediaSessionManager.observeVolumeChanges(enabled)
|
|
102
95
|
}
|
|
103
96
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
promise!!.resolve(res)
|
|
97
|
+
override fun requestRecordingPermissions(promise: Promise) {
|
|
98
|
+
val permissionRequestListener = PermissionRequestListener(promise)
|
|
99
|
+
MediaSessionManager.requestRecordingPermissions(permissionRequestListener)
|
|
108
100
|
}
|
|
109
101
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
val res = MediaSessionManager.checkRecordingPermissions()
|
|
113
|
-
promise!!.resolve(res)
|
|
102
|
+
override fun checkRecordingPermissions(promise: Promise) {
|
|
103
|
+
promise.resolve(MediaSessionManager.checkRecordingPermissions())
|
|
114
104
|
}
|
|
115
105
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.swmansion.audioapi.system
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
-
import android.app.Activity
|
|
5
4
|
import android.app.NotificationChannel
|
|
6
5
|
import android.app.NotificationManager
|
|
7
6
|
import android.content.ComponentName
|
|
@@ -16,12 +15,14 @@ import android.os.IBinder
|
|
|
16
15
|
import android.support.v4.media.session.MediaSessionCompat
|
|
17
16
|
import android.util.Log
|
|
18
17
|
import androidx.annotation.RequiresApi
|
|
19
|
-
import androidx.core.app.ActivityCompat
|
|
20
18
|
import androidx.core.app.NotificationCompat
|
|
21
19
|
import androidx.core.content.ContextCompat
|
|
22
20
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
23
21
|
import com.facebook.react.bridge.ReadableMap
|
|
22
|
+
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
23
|
+
import com.facebook.react.modules.core.PermissionListener
|
|
24
24
|
import com.swmansion.audioapi.AudioAPIModule
|
|
25
|
+
import com.swmansion.audioapi.system.PermissionRequestListener.Companion.RECORDING_REQUEST_CODE
|
|
25
26
|
import java.lang.ref.WeakReference
|
|
26
27
|
|
|
27
28
|
object MediaSessionManager {
|
|
@@ -158,14 +159,13 @@ object MediaSessionManager {
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
fun requestRecordingPermissions(
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
fun requestRecordingPermissions(permissionListener: PermissionListener) {
|
|
163
|
+
val permissionAwareActivity = reactContext.get()!!.currentActivity as PermissionAwareActivity
|
|
164
|
+
permissionAwareActivity.requestPermissions(arrayOf(Manifest.permission.RECORD_AUDIO), RECORDING_REQUEST_CODE, permissionListener)
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
fun checkRecordingPermissions(): String =
|
|
167
|
-
if (
|
|
168
|
-
reactContext.get()!!,
|
|
168
|
+
if (reactContext.get()!!.checkSelfPermission(
|
|
169
169
|
Manifest.permission.RECORD_AUDIO,
|
|
170
170
|
) == PackageManager.PERMISSION_GRANTED
|
|
171
171
|
) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.swmansion.audioapi.system
|
|
2
|
+
|
|
3
|
+
import android.content.pm.PackageManager
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.modules.core.PermissionListener
|
|
6
|
+
|
|
7
|
+
class PermissionRequestListener(
|
|
8
|
+
private val promise: Promise,
|
|
9
|
+
) : PermissionListener {
|
|
10
|
+
companion object {
|
|
11
|
+
const val RECORDING_REQUEST_CODE = 1234
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun onRequestPermissionsResult(
|
|
15
|
+
requestCode: Int,
|
|
16
|
+
permissions: Array<String>,
|
|
17
|
+
grantResults: IntArray,
|
|
18
|
+
): Boolean {
|
|
19
|
+
if (requestCode == RECORDING_REQUEST_CODE) {
|
|
20
|
+
if (grantResults.isEmpty()) {
|
|
21
|
+
this.promise.resolve("Undetermined")
|
|
22
|
+
} else {
|
|
23
|
+
val granted = grantResults[0] == PackageManager.PERMISSION_GRANTED
|
|
24
|
+
if (granted) {
|
|
25
|
+
this.promise.resolve("Granted")
|
|
26
|
+
} else {
|
|
27
|
+
this.promise.resolve("Denied")
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -49,7 +49,8 @@ class BaseAudioContextHostObject : public JsiHostObject {
|
|
|
49
49
|
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createPeriodicWave),
|
|
50
50
|
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, createAnalyser),
|
|
51
51
|
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, decodeAudioData),
|
|
52
|
-
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, decodeAudioDataSource)
|
|
52
|
+
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, decodeAudioDataSource),
|
|
53
|
+
JSI_EXPORT_FUNCTION(BaseAudioContextHostObject, decodePCMAudioDataInBase64));
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
JSI_PROPERTY_GETTER(destination) {
|
|
@@ -163,13 +164,14 @@ JSI_HOST_FUNCTION(createBufferQueueSource) {
|
|
|
163
164
|
auto promise = promiseVendor_->createPromise([this, sourcePath](std::shared_ptr<Promise> promise) {
|
|
164
165
|
std::thread([this, sourcePath, promise = std::move(promise)]() {
|
|
165
166
|
auto results = context_->decodeAudioDataSource(sourcePath);
|
|
166
|
-
auto audioBufferHostObject = std::make_shared<AudioBufferHostObject>(results);
|
|
167
167
|
|
|
168
168
|
if (!results) {
|
|
169
169
|
promise->reject("Failed to decode audio data source.");
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
auto audioBufferHostObject = std::make_shared<AudioBufferHostObject>(results);
|
|
174
|
+
|
|
173
175
|
promise->resolve([audioBufferHostObject = std::move(audioBufferHostObject)](jsi::Runtime &runtime) {
|
|
174
176
|
auto jsiObject = jsi::Object::createFromHostObject(runtime, audioBufferHostObject);
|
|
175
177
|
jsiObject.setExternalMemoryPressure(runtime, audioBufferHostObject->getSizeInBytes());
|
|
@@ -189,13 +191,14 @@ JSI_HOST_FUNCTION(createBufferQueueSource) {
|
|
|
189
191
|
auto promise = promiseVendor_->createPromise([this, data, size](std::shared_ptr<Promise> promise) {
|
|
190
192
|
std::thread([this, data, size, promise = std::move(promise)]() {
|
|
191
193
|
auto results = context_->decodeAudioData(data, size);
|
|
192
|
-
auto audioBufferHostObject = std::make_shared<AudioBufferHostObject>(results);
|
|
193
194
|
|
|
194
195
|
if (!results) {
|
|
195
196
|
promise->reject("Failed to decode audio data source.");
|
|
196
197
|
return;
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
auto audioBufferHostObject = std::make_shared<AudioBufferHostObject>(results);
|
|
201
|
+
|
|
199
202
|
promise->resolve([audioBufferHostObject = std::move(audioBufferHostObject)](jsi::Runtime &runtime) {
|
|
200
203
|
auto jsiObject = jsi::Object::createFromHostObject(runtime, audioBufferHostObject);
|
|
201
204
|
jsiObject.setExternalMemoryPressure(runtime, audioBufferHostObject->getSizeInBytes());
|
|
@@ -207,6 +210,31 @@ JSI_HOST_FUNCTION(createBufferQueueSource) {
|
|
|
207
210
|
return promise;
|
|
208
211
|
}
|
|
209
212
|
|
|
213
|
+
JSI_HOST_FUNCTION(decodePCMAudioDataInBase64) {
|
|
214
|
+
auto b64 = args[0].getString(runtime).utf8(runtime);
|
|
215
|
+
|
|
216
|
+
auto promise = promiseVendor_->createPromise([this, b64](std::shared_ptr<Promise> promise) {
|
|
217
|
+
std::thread([this, b64, promise = std::move(promise)]() {
|
|
218
|
+
auto results = context_->decodeWithPCMInBase64(b64);
|
|
219
|
+
|
|
220
|
+
if (!results) {
|
|
221
|
+
promise->reject("Failed to decode audio data source.");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
auto audioBufferHostObject = std::make_shared<AudioBufferHostObject>(results);
|
|
226
|
+
|
|
227
|
+
promise->resolve([audioBufferHostObject = std::move(audioBufferHostObject)](jsi::Runtime &runtime) {
|
|
228
|
+
auto jsiObject = jsi::Object::createFromHostObject(runtime, audioBufferHostObject);
|
|
229
|
+
jsiObject.setExternalMemoryPressure(runtime, audioBufferHostObject->getSizeInBytes());
|
|
230
|
+
return jsiObject;
|
|
231
|
+
});
|
|
232
|
+
}).detach();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return promise;
|
|
236
|
+
}
|
|
237
|
+
|
|
210
238
|
protected:
|
|
211
239
|
std::shared_ptr<BaseAudioContext> context_;
|
|
212
240
|
std::shared_ptr<PromiseVendor> promiseVendor_;
|
|
@@ -131,6 +131,17 @@ std::shared_ptr<AudioBuffer> BaseAudioContext::decodeAudioData(
|
|
|
131
131
|
return std::make_shared<AudioBuffer>(audioBus);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
std::shared_ptr<AudioBuffer> BaseAudioContext::decodeWithPCMInBase64(
|
|
135
|
+
const std::string &data) {
|
|
136
|
+
auto audioBus = audioDecoder_->decodeWithPCMInBase64(data);
|
|
137
|
+
|
|
138
|
+
if (!audioBus) {
|
|
139
|
+
return nullptr;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return std::make_shared<AudioBuffer>(audioBus);
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
AudioNodeManager *BaseAudioContext::getNodeManager() {
|
|
135
146
|
return nodeManager_.get();
|
|
136
147
|
}
|
|
@@ -56,6 +56,7 @@ class BaseAudioContext {
|
|
|
56
56
|
|
|
57
57
|
std::shared_ptr<AudioBuffer> decodeAudioDataSource(const std::string &path);
|
|
58
58
|
std::shared_ptr<AudioBuffer> decodeAudioData(const void *data, size_t size);
|
|
59
|
+
std::shared_ptr<AudioBuffer> decodeWithPCMInBase64(const std::string &data);
|
|
59
60
|
|
|
60
61
|
std::shared_ptr<PeriodicWave> getBasicWaveForm(OscillatorType type);
|
|
61
62
|
[[nodiscard]] float getNyquistFrequency() const;
|
|
@@ -100,7 +100,7 @@ void AudioScheduledSourceNode::updatePlaybackInfo(
|
|
|
100
100
|
assert(nonSilentFramesToProcess <= framesToProcess);
|
|
101
101
|
|
|
102
102
|
// stop will happen in the same render quantum
|
|
103
|
-
if (stopFrame
|
|
103
|
+
if (stopFrame <= lastFrame && stopFrame >= firstFrame) {
|
|
104
104
|
playbackState_ = PlaybackState::STOP_SCHEDULED;
|
|
105
105
|
processingBus->zero(stopFrame - firstFrame, lastFrame - stopFrame);
|
|
106
106
|
}
|
|
@@ -13,6 +13,7 @@ class AudioDecoder {
|
|
|
13
13
|
|
|
14
14
|
[[nodiscard]] std::shared_ptr<AudioBus> decodeWithFilePath(const std::string &path) const;
|
|
15
15
|
[[nodiscard]] std::shared_ptr<AudioBus> decodeWithMemoryBlock(const void *data, size_t size) const;
|
|
16
|
+
[[nodiscard]] std::shared_ptr<AudioBus> decodeWithPCMInBase64(const std::string &data) const;
|
|
16
17
|
|
|
17
18
|
private:
|
|
18
19
|
float sampleRate_;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/*
|
|
2
|
+
base64.h
|
|
3
|
+
|
|
4
|
+
base64 encoding and decoding with C++.
|
|
5
|
+
More information at
|
|
6
|
+
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp
|
|
7
|
+
|
|
8
|
+
Version: 2.rc.09 (release candidate)
|
|
9
|
+
|
|
10
|
+
Copyright (C) 2004-2017, 2020-2022 René Nyffenegger
|
|
11
|
+
|
|
12
|
+
This source code is provided 'as-is', without any express or implied
|
|
13
|
+
warranty. In no event will the author be held liable for any damages
|
|
14
|
+
arising from the use of this software.
|
|
15
|
+
|
|
16
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
17
|
+
including commercial applications, and to alter it and redistribute it
|
|
18
|
+
freely, subject to the following restrictions:
|
|
19
|
+
|
|
20
|
+
1. The origin of this source code must not be misrepresented; you must not
|
|
21
|
+
claim that you wrote the original source code. If you use this source code
|
|
22
|
+
in a product, an acknowledgment in the product documentation would be
|
|
23
|
+
appreciated but is not required.
|
|
24
|
+
|
|
25
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
26
|
+
misrepresented as being the original source code.
|
|
27
|
+
|
|
28
|
+
3. This notice may not be removed or altered from any source distribution.
|
|
29
|
+
|
|
30
|
+
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Copyright (C) 2023 Kevin Heifner
|
|
34
|
+
*
|
|
35
|
+
* Modified to be header only.
|
|
36
|
+
* Templated for std::string, std::string_view, std::vector<char> and other char containers.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
#pragma once
|
|
40
|
+
|
|
41
|
+
#include <algorithm>
|
|
42
|
+
#include <string>
|
|
43
|
+
#include <string_view>
|
|
44
|
+
#include <stdexcept>
|
|
45
|
+
|
|
46
|
+
// Interface:
|
|
47
|
+
// Defaults allow for use:
|
|
48
|
+
// std::string s = "foobar";
|
|
49
|
+
// std::string encoded = base64_encode(s);
|
|
50
|
+
// std::string_view sv = "foobar";
|
|
51
|
+
// std::string encoded = base64_encode(sv);
|
|
52
|
+
// std::vector<char> vc = {'f', 'o', 'o'};
|
|
53
|
+
// std::string encoded = base64_encode(vc);
|
|
54
|
+
//
|
|
55
|
+
// Also allows for user provided char containers and specified return types:
|
|
56
|
+
// std::string s = "foobar";
|
|
57
|
+
// std::vector<char> encoded = base64_encode<std::vector<char>>(s);
|
|
58
|
+
|
|
59
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
60
|
+
RetString base64_encode(const String& s, bool url = false);
|
|
61
|
+
|
|
62
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
63
|
+
RetString base64_encode_pem(const String& s);
|
|
64
|
+
|
|
65
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
66
|
+
RetString base64_encode_mime(const String& s);
|
|
67
|
+
|
|
68
|
+
template <typename RetString = std::string, typename String = std::string>
|
|
69
|
+
RetString base64_decode(const String& s, bool remove_linebreaks = false);
|
|
70
|
+
|
|
71
|
+
template <typename RetString = std::string>
|
|
72
|
+
RetString base64_encode(const unsigned char* s, size_t len, bool url = false);
|
|
73
|
+
|
|
74
|
+
namespace detail {
|
|
75
|
+
//
|
|
76
|
+
// Depending on the url parameter in base64_chars, one of
|
|
77
|
+
// two sets of base64 characters needs to be chosen.
|
|
78
|
+
// They differ in their last two characters.
|
|
79
|
+
//
|
|
80
|
+
constexpr const char* to_base64_chars[2] = {
|
|
81
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
82
|
+
"abcdefghijklmnopqrstuvwxyz"
|
|
83
|
+
"0123456789"
|
|
84
|
+
"+/",
|
|
85
|
+
|
|
86
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
87
|
+
"abcdefghijklmnopqrstuvwxyz"
|
|
88
|
+
"0123456789"
|
|
89
|
+
"-_"};
|
|
90
|
+
|
|
91
|
+
constexpr unsigned char from_base64_chars[256] = {
|
|
92
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
93
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
94
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 62, 64, 63,
|
|
95
|
+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
|
96
|
+
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
97
|
+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 63,
|
|
98
|
+
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
|
99
|
+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
|
100
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
101
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
102
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
103
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
104
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
105
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
106
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
|
107
|
+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
inline unsigned int pos_of_char(const unsigned char chr) {
|
|
111
|
+
//
|
|
112
|
+
// Return the position of chr within base64_encode()
|
|
113
|
+
//
|
|
114
|
+
|
|
115
|
+
if (from_base64_chars[chr] != 64) return from_base64_chars[chr];
|
|
116
|
+
|
|
117
|
+
//
|
|
118
|
+
// 2020-10-23: Throw std::exception rather than const char*
|
|
119
|
+
//(Pablo Martin-Gomez, https://github.com/Bouska)
|
|
120
|
+
//
|
|
121
|
+
throw std::runtime_error("Input is not valid base64-encoded data.");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
template <typename RetString, typename String>
|
|
125
|
+
inline RetString insert_linebreaks(const String& str, size_t distance) {
|
|
126
|
+
//
|
|
127
|
+
// Provided by https://github.com/JomaCorpFX, adapted by Rene & Kevin
|
|
128
|
+
//
|
|
129
|
+
if (!str.size()) {
|
|
130
|
+
return RetString{};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (distance < str.size()) {
|
|
134
|
+
size_t pos = distance;
|
|
135
|
+
String s{str};
|
|
136
|
+
while (pos < s.size()) {
|
|
137
|
+
s.insert(pos, "\n");
|
|
138
|
+
pos += distance + 1;
|
|
139
|
+
}
|
|
140
|
+
return s;
|
|
141
|
+
} else {
|
|
142
|
+
return str;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
template <typename RetString, typename String, unsigned int line_length>
|
|
147
|
+
inline RetString encode_with_line_breaks(String s) {
|
|
148
|
+
return insert_linebreaks<RetString, String>(base64_encode(s, false), line_length);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
template <typename RetString, typename String>
|
|
152
|
+
inline RetString encode_pem(String s) {
|
|
153
|
+
return encode_with_line_breaks<RetString, String, 64>(s);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
template <typename RetString, typename String>
|
|
157
|
+
inline RetString encode_mime(String s) {
|
|
158
|
+
return encode_with_line_breaks<RetString, String, 76>(s);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
template <typename RetString, typename String>
|
|
162
|
+
inline RetString encode(String s, bool url) {
|
|
163
|
+
return base64_encode<RetString>(reinterpret_cast<const unsigned char*>(s.data()), s.size(), url);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
} // namespace detail
|
|
167
|
+
|
|
168
|
+
template <typename RetString>
|
|
169
|
+
inline RetString base64_encode(const unsigned char* bytes_to_encode, size_t in_len, bool url) {
|
|
170
|
+
size_t len_encoded = (in_len + 2) / 3 * 4;
|
|
171
|
+
|
|
172
|
+
unsigned char trailing_char = url ? '.' : '=';
|
|
173
|
+
|
|
174
|
+
//
|
|
175
|
+
// Choose set of base64 characters. They differ
|
|
176
|
+
// for the last two positions, depending on the url
|
|
177
|
+
// parameter.
|
|
178
|
+
// A bool (as is the parameter url) is guaranteed
|
|
179
|
+
// to evaluate to either 0 or 1 in C++ therefore,
|
|
180
|
+
// the correct character set is chosen by subscripting
|
|
181
|
+
// base64_chars with url.
|
|
182
|
+
//
|
|
183
|
+
const char *base64_chars_ = detail::to_base64_chars[url];
|
|
184
|
+
|
|
185
|
+
RetString ret;
|
|
186
|
+
ret.reserve(len_encoded);
|
|
187
|
+
|
|
188
|
+
unsigned int pos = 0;
|
|
189
|
+
|
|
190
|
+
while (pos < in_len) {
|
|
191
|
+
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0xfc) >> 2]);
|
|
192
|
+
|
|
193
|
+
if (pos + 1 < in_len) {
|
|
194
|
+
ret.push_back(base64_chars_[((bytes_to_encode[pos + 0] & 0x03) << 4) +
|
|
195
|
+
((bytes_to_encode[pos + 1] & 0xf0) >> 4)]);
|
|
196
|
+
|
|
197
|
+
if (pos + 2 < in_len) {
|
|
198
|
+
ret.push_back(base64_chars_[((bytes_to_encode[pos + 1] & 0x0f) << 2) +
|
|
199
|
+
((bytes_to_encode[pos + 2] & 0xc0) >> 6)]);
|
|
200
|
+
ret.push_back(base64_chars_[bytes_to_encode[pos + 2] & 0x3f]);
|
|
201
|
+
} else {
|
|
202
|
+
ret.push_back(base64_chars_[(bytes_to_encode[pos + 1] & 0x0f) << 2]);
|
|
203
|
+
ret.push_back(trailing_char);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
ret.push_back(base64_chars_[(bytes_to_encode[pos + 0] & 0x03) << 4]);
|
|
207
|
+
ret.push_back(trailing_char);
|
|
208
|
+
ret.push_back(trailing_char);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
pos += 3;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return ret;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
namespace detail {
|
|
218
|
+
|
|
219
|
+
template <typename RetString, typename String>
|
|
220
|
+
inline RetString decode(const String& encoded_string, bool remove_linebreaks) {
|
|
221
|
+
static_assert(!std::is_same<RetString, std::string_view>::value,
|
|
222
|
+
"RetString should not be std::string_view");
|
|
223
|
+
|
|
224
|
+
//
|
|
225
|
+
// decode(…) is templated so that it can be used with String = const std::string&
|
|
226
|
+
// or std::string_view (requires at least C++17)
|
|
227
|
+
//
|
|
228
|
+
|
|
229
|
+
if (encoded_string.empty())
|
|
230
|
+
return RetString{};
|
|
231
|
+
|
|
232
|
+
if (remove_linebreaks) {
|
|
233
|
+
String copy{encoded_string};
|
|
234
|
+
|
|
235
|
+
copy.erase(std::remove(copy.begin(), copy.end(), '\n'), copy.end());
|
|
236
|
+
|
|
237
|
+
return base64_decode<RetString, String>(copy, false);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
size_t length_of_string = encoded_string.size();
|
|
241
|
+
size_t pos = 0;
|
|
242
|
+
|
|
243
|
+
//
|
|
244
|
+
// The approximate length (bytes) of the decoded string might be one or
|
|
245
|
+
// two bytes smaller, depending on the amount of trailing equal signs
|
|
246
|
+
// in the encoded string. This approximation is needed to reserve
|
|
247
|
+
// enough space in the string to be returned.
|
|
248
|
+
//
|
|
249
|
+
size_t approx_length_of_decoded_string = length_of_string / 4 * 3;
|
|
250
|
+
RetString ret;
|
|
251
|
+
ret.reserve(approx_length_of_decoded_string);
|
|
252
|
+
|
|
253
|
+
while (pos < length_of_string) {
|
|
254
|
+
//
|
|
255
|
+
// Iterate over encoded input string in chunks. The size of all
|
|
256
|
+
// chunks except the last one is 4 bytes.
|
|
257
|
+
//
|
|
258
|
+
// The last chunk might be padded with equal signs or dots
|
|
259
|
+
// in order to make it 4 bytes in size as well, but this
|
|
260
|
+
// is not required as per RFC 2045.
|
|
261
|
+
//
|
|
262
|
+
// All chunks except the last one produce three output bytes.
|
|
263
|
+
//
|
|
264
|
+
// The last chunk produces at least one and up to three bytes.
|
|
265
|
+
//
|
|
266
|
+
|
|
267
|
+
size_t pos_of_char_1 = pos_of_char(encoded_string.at(pos + 1));
|
|
268
|
+
|
|
269
|
+
//
|
|
270
|
+
// Emit the first output byte that is produced in each chunk:
|
|
271
|
+
//
|
|
272
|
+
ret.push_back(static_cast<typename RetString::value_type>(((pos_of_char(encoded_string.at(pos + 0))) << 2) + ((pos_of_char_1 & 0x30) >> 4)));
|
|
273
|
+
|
|
274
|
+
if ((pos + 2 < length_of_string) &&
|
|
275
|
+
// Check for data that is not padded with equal signs (which is allowed by RFC 2045)
|
|
276
|
+
encoded_string.at(pos + 2) != '=' &&
|
|
277
|
+
encoded_string.at(pos + 2) != '.' ) { // accept URL-safe base 64 strings, too, so check for '.' also.
|
|
278
|
+
//
|
|
279
|
+
// Emit a chunk's second byte (which might not be produced in the last chunk).
|
|
280
|
+
//
|
|
281
|
+
unsigned int pos_of_char_2 = pos_of_char(encoded_string.at(pos + 2));
|
|
282
|
+
ret.push_back(static_cast<typename RetString::value_type>(((pos_of_char_1 & 0x0f) << 4) + ((pos_of_char_2 & 0x3c) >> 2)));
|
|
283
|
+
|
|
284
|
+
if ((pos + 3 < length_of_string) &&
|
|
285
|
+
encoded_string.at(pos + 3) != '=' &&
|
|
286
|
+
encoded_string.at(pos + 3) != '.' ) {
|
|
287
|
+
//
|
|
288
|
+
// Emit a chunk's third byte (which might not be produced in the last chunk).
|
|
289
|
+
//
|
|
290
|
+
ret.push_back(static_cast<typename RetString::value_type>(((pos_of_char_2 & 0x03) << 6) + pos_of_char(encoded_string.at(pos + 3))));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
pos += 4;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return ret;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
} // namespace detail
|
|
301
|
+
|
|
302
|
+
template <typename RetString, typename String>
|
|
303
|
+
inline RetString base64_decode(const String& s, bool remove_linebreaks) {
|
|
304
|
+
return detail::decode<RetString, String>(s, remove_linebreaks);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
template <typename RetString, typename String>
|
|
308
|
+
inline RetString base64_encode(const String& s, bool url) {
|
|
309
|
+
return detail::encode<RetString, String>(s, url);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
template <typename RetString, typename String>
|
|
313
|
+
inline RetString base64_encode_pem (const String& s) {
|
|
314
|
+
return detail::encode_pem<RetString, String>(s);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
template <typename RetString, typename String>
|
|
318
|
+
inline RetString base64_encode_mime(const String& s) {
|
|
319
|
+
return detail::encode_mime<RetString, String>(s);
|
|
320
|
+
}
|
|
@@ -131,15 +131,13 @@ RCT_EXPORT_METHOD(
|
|
|
131
131
|
requestRecordingPermissions : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)
|
|
132
132
|
reject)
|
|
133
133
|
{
|
|
134
|
-
|
|
135
|
-
resolve(res);
|
|
134
|
+
[self.audioSessionManager requestRecordingPermissions:resolve reject:reject];
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
RCT_EXPORT_METHOD(
|
|
139
138
|
checkRecordingPermissions : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)reject)
|
|
140
139
|
{
|
|
141
|
-
|
|
142
|
-
resolve(res);
|
|
140
|
+
[self.audioSessionManager checkRecordingPermissions:resolve reject:reject];
|
|
143
141
|
}
|
|
144
142
|
|
|
145
143
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
#import <audioapi/libs/miniaudio/miniaudio.h>
|
|
3
3
|
|
|
4
4
|
#include <audioapi/core/utils/AudioDecoder.h>
|
|
5
|
+
#include <audioapi/dsp/VectorMath.h>
|
|
6
|
+
#include <audioapi/libs/base64/base64.h>
|
|
5
7
|
#include <audioapi/utils/AudioArray.h>
|
|
6
8
|
#include <audioapi/utils/AudioBus.h>
|
|
7
9
|
|
|
@@ -94,4 +96,25 @@ std::shared_ptr<AudioBus> AudioDecoder::decodeWithMemoryBlock(const void *data,
|
|
|
94
96
|
|
|
95
97
|
return audioBus;
|
|
96
98
|
}
|
|
99
|
+
|
|
100
|
+
std::shared_ptr<AudioBus> AudioDecoder::decodeWithPCMInBase64(const std::string &data) const
|
|
101
|
+
{
|
|
102
|
+
auto decodedData = base64_decode(data, false);
|
|
103
|
+
|
|
104
|
+
const auto uint8Data = reinterpret_cast<uint8_t *>(decodedData.data());
|
|
105
|
+
size_t frameCount = decodedData.size() / 2;
|
|
106
|
+
|
|
107
|
+
auto audioBus = std::make_shared<AudioBus>(frameCount, 1, sampleRate_);
|
|
108
|
+
auto channelData = audioBus->getChannel(0)->getData();
|
|
109
|
+
|
|
110
|
+
for (size_t i = 0; i < frameCount; ++i) {
|
|
111
|
+
auto sample = static_cast<int16_t>((uint8Data[i * 2 + 1] << 8) | uint8Data[i * 2]);
|
|
112
|
+
channelData[i] = static_cast<float>(sample);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
dsp::multiplyByScalar(channelData, 1.0f / 32768.0f, channelData, frameCount);
|
|
116
|
+
|
|
117
|
+
return audioBus;
|
|
118
|
+
}
|
|
119
|
+
|
|
97
120
|
} // namespace audioapi
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
@property (nonatomic, strong) AVAudioEngine *audioEngine;
|
|
11
11
|
@property (nonatomic, strong) NSMutableDictionary *sourceNodes;
|
|
12
12
|
@property (nonatomic, strong) NSMutableDictionary *sourceFormats;
|
|
13
|
+
@property (nonatomic, strong) NSMutableDictionary *sourceStates;
|
|
13
14
|
@property (nonatomic, strong) AVAudioSinkNode *inputNode;
|
|
14
15
|
@property (nonatomic, weak) AudioSessionManager *sessionManager;
|
|
15
16
|
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
- (bool)rebuildAudioEngine;
|
|
21
22
|
- (void)startEngine;
|
|
22
23
|
- (void)stopEngine;
|
|
23
|
-
- (void)pauseEngine;
|
|
24
|
+
- (void)pauseEngine:(NSString *)sourceNodeId;
|
|
24
25
|
- (bool)isRunning;
|
|
25
26
|
|
|
26
27
|
- (NSString *)attachSourceNode:(AVAudioSourceNode *)sourceNode format:(AVAudioFormat *)format;
|
|
@@ -29,7 +30,4 @@
|
|
|
29
30
|
- (void)attachInputNode:(AVAudioSinkNode *)inputNode;
|
|
30
31
|
- (void)detachInputNode;
|
|
31
32
|
|
|
32
|
-
- (void)startIfNecessary;
|
|
33
|
-
- (void)stopIfNecessary;
|
|
34
|
-
|
|
35
33
|
@end
|
|
@@ -18,6 +18,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
18
18
|
|
|
19
19
|
self.sourceNodes = [[NSMutableDictionary alloc] init];
|
|
20
20
|
self.sourceFormats = [[NSMutableDictionary alloc] init];
|
|
21
|
+
self.sourceStates = [[NSMutableDictionary alloc] init];
|
|
21
22
|
|
|
22
23
|
self.sessionManager = sessionManager;
|
|
23
24
|
}
|
|
@@ -37,6 +38,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
37
38
|
self.audioEngine = nil;
|
|
38
39
|
self.sourceNodes = nil;
|
|
39
40
|
self.sourceFormats = nil;
|
|
41
|
+
self.sourceStates = nil;
|
|
40
42
|
self.inputNode = nil;
|
|
41
43
|
|
|
42
44
|
[self.sessionManager setActive:false];
|
|
@@ -74,8 +76,8 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
[self.audioEngine startAndReturnError:&error];
|
|
78
79
|
[self.sessionManager setActive:true];
|
|
80
|
+
[self.audioEngine startAndReturnError:&error];
|
|
79
81
|
|
|
80
82
|
if (error != nil) {
|
|
81
83
|
NSLog(@"Error while starting the audio engine: %@", [error debugDescription]);
|
|
@@ -92,14 +94,14 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
92
94
|
[self.audioEngine stop];
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
- (void)pauseEngine
|
|
97
|
+
- (void)pauseEngine:(NSString *)sourceNodeId
|
|
96
98
|
{
|
|
97
|
-
NSLog(@"[AudioEngine] pauseEngine");
|
|
98
99
|
if (![self.audioEngine isRunning]) {
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
[self.
|
|
103
|
+
[self.sourceStates setValue:@false forKey:sourceNodeId];
|
|
104
|
+
[self pauseIfNecessary];
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
- (bool)isRunning
|
|
@@ -114,6 +116,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
114
116
|
|
|
115
117
|
[self.sourceNodes setValue:sourceNode forKey:sourceNodeId];
|
|
116
118
|
[self.sourceFormats setValue:format forKey:sourceNodeId];
|
|
119
|
+
[self.sourceStates setValue:@true forKey:sourceNodeId];
|
|
117
120
|
|
|
118
121
|
[self.audioEngine attachNode:sourceNode];
|
|
119
122
|
[self.audioEngine connect:sourceNode to:self.audioEngine.mainMixerNode format:format];
|
|
@@ -133,6 +136,7 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
133
136
|
|
|
134
137
|
[self.sourceNodes removeObjectForKey:sourceNodeId];
|
|
135
138
|
[self.sourceFormats removeObjectForKey:sourceNodeId];
|
|
139
|
+
[self.sourceStates removeObjectForKey:sourceNodeId];
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
[self stopIfNecessary];
|
|
@@ -180,4 +184,21 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
|
|
187
|
+
- (void)pauseIfNecessary
|
|
188
|
+
{
|
|
189
|
+
if (![self isRunning]) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (NSString *sourceId in self.sourceStates) {
|
|
194
|
+
if ([self.sourceStates[sourceId] boolValue]) {
|
|
195
|
+
NSLog(@"state %c", self.sourceStates[sourceId]);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
NSLog(@"[AudioEngine] pauseEngine");
|
|
201
|
+
[self.audioEngine pause];
|
|
202
|
+
}
|
|
203
|
+
|
|
183
204
|
@end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#import <AVFoundation/AVFoundation.h>
|
|
4
4
|
#import <Foundation/Foundation.h>
|
|
5
|
+
#import <React/RCTBridgeModule.h>
|
|
5
6
|
|
|
6
7
|
@interface AudioSessionManager : NSObject
|
|
7
8
|
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
- (NSNumber *)getDevicePreferredSampleRate;
|
|
21
22
|
- (void)setAudioSessionOptions:(NSString *)category mode:(NSString *)mode options:(NSArray *)options;
|
|
22
23
|
- (bool)setActive:(bool)active;
|
|
23
|
-
- (
|
|
24
|
-
- (
|
|
24
|
+
- (void)requestRecordingPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
|
|
25
|
+
- (void)checkRecordingPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
|
|
25
26
|
|
|
26
27
|
@end
|
|
@@ -175,11 +175,62 @@
|
|
|
175
175
|
return true;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
- (
|
|
178
|
+
- (void)requestRecordingPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
|
|
179
179
|
{
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
if (@available(iOS 17, *)) {
|
|
181
|
+
[AVAudioSession.sharedInstance requestRecordPermission:^(BOOL granted) {
|
|
182
|
+
if (granted) {
|
|
183
|
+
resolve(@"Granted");
|
|
184
|
+
} else {
|
|
185
|
+
resolve(@"Denied");
|
|
186
|
+
}
|
|
187
|
+
}];
|
|
188
|
+
} else {
|
|
189
|
+
[self.audioSession requestRecordPermission:^(BOOL granted) {
|
|
190
|
+
if (granted) {
|
|
191
|
+
resolve(@"Granted");
|
|
192
|
+
} else {
|
|
193
|
+
resolve(@"Denied");
|
|
194
|
+
}
|
|
195
|
+
}];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
- (void)checkRecordingPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
|
|
200
|
+
{
|
|
201
|
+
if (@available(iOS 17, *)) {
|
|
202
|
+
NSInteger res = [[AVAudioApplication sharedInstance] recordPermission];
|
|
203
|
+
switch (res) {
|
|
204
|
+
case AVAudioApplicationRecordPermissionUndetermined:
|
|
205
|
+
resolve(@"Undetermined");
|
|
206
|
+
break;
|
|
207
|
+
case AVAudioApplicationRecordPermissionGranted:
|
|
208
|
+
resolve(@"Granted");
|
|
209
|
+
break;
|
|
210
|
+
case AVAudioApplicationRecordPermissionDenied:
|
|
211
|
+
resolve(@"Denied");
|
|
212
|
+
break;
|
|
213
|
+
default:
|
|
214
|
+
resolve(@"Undetermined");
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
NSInteger res = [self.audioSession recordPermission];
|
|
219
|
+
switch (res) {
|
|
220
|
+
case AVAudioSessionRecordPermissionUndetermined:
|
|
221
|
+
resolve(@"Undetermined");
|
|
222
|
+
break;
|
|
223
|
+
case AVAudioSessionRecordPermissionGranted:
|
|
224
|
+
resolve(@"Granted");
|
|
225
|
+
break;
|
|
226
|
+
case AVAudioSessionRecordPermissionDenied:
|
|
227
|
+
resolve(@"Denied");
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
resolve(@"Undetermined");
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
183
234
|
}
|
|
184
235
|
|
|
185
236
|
- (NSString *)checkRecordingPermissions
|
|
@@ -76,8 +76,14 @@ class BaseAudioContext {
|
|
|
76
76
|
}
|
|
77
77
|
return new _AudioBuffer.default(await this.context.decodeAudioDataSource(sourcePath));
|
|
78
78
|
}
|
|
79
|
-
async decodeAudioData(
|
|
80
|
-
|
|
79
|
+
async decodeAudioData(data) {
|
|
80
|
+
// pcm data in base64
|
|
81
|
+
if (typeof data === 'string') {
|
|
82
|
+
return new _AudioBuffer.default(await this.context.decodePCMAudioDataInBase64(data));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// data in array buffer
|
|
86
|
+
return new _AudioBuffer.default(await this.context.decodeAudioData(new Uint8Array(data)));
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
exports.default = BaseAudioContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_AudioDestinationNode","_interopRequireDefault","require","_OscillatorNode","_GainNode","_StereoPannerNode","_BiquadFilterNode","_AudioBufferSourceNode","_AudioBuffer","_PeriodicWave","_AnalyserNode","_AudioBufferQueueSourceNode","_errors","e","__esModule","default","BaseAudioContext","constructor","context","destination","AudioDestinationNode","sampleRate","currentTime","state","createOscillator","OscillatorNode","createGain","GainNode","createStereoPanner","StereoPannerNode","createBiquadFilter","BiquadFilterNode","createBufferSource","options","pitchCorrection","AudioBufferSourceNode","createBufferQueueSource","AudioBufferQueueSourceNode","createBuffer","numOfChannels","length","NotSupportedError","AudioBuffer","createPeriodicWave","real","imag","constraints","InvalidAccessError","disableNormalization","PeriodicWave","createAnalyser","AnalyserNode","decodeAudioDataSource","sourcePath","startsWith","replace","decodeAudioData","
|
|
1
|
+
{"version":3,"names":["_AudioDestinationNode","_interopRequireDefault","require","_OscillatorNode","_GainNode","_StereoPannerNode","_BiquadFilterNode","_AudioBufferSourceNode","_AudioBuffer","_PeriodicWave","_AnalyserNode","_AudioBufferQueueSourceNode","_errors","e","__esModule","default","BaseAudioContext","constructor","context","destination","AudioDestinationNode","sampleRate","currentTime","state","createOscillator","OscillatorNode","createGain","GainNode","createStereoPanner","StereoPannerNode","createBiquadFilter","BiquadFilterNode","createBufferSource","options","pitchCorrection","AudioBufferSourceNode","createBufferQueueSource","AudioBufferQueueSourceNode","createBuffer","numOfChannels","length","NotSupportedError","AudioBuffer","createPeriodicWave","real","imag","constraints","InvalidAccessError","disableNormalization","PeriodicWave","createAnalyser","AnalyserNode","decodeAudioDataSource","sourcePath","startsWith","replace","decodeAudioData","data","decodePCMAudioDataInBase64","Uint8Array","exports"],"sourceRoot":"../../../src","sources":["core/BaseAudioContext.ts"],"mappings":";;;;;;AAMA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,iBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,iBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,sBAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,aAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,aAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,2BAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,OAAA,GAAAV,OAAA;AAAkE,SAAAD,uBAAAY,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEnD,MAAMG,gBAAgB,CAAC;EAKpCC,WAAWA,CAACC,OAA0B,EAAE;IACtC,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,WAAW,GAAG,IAAIC,6BAAoB,CAAC,IAAI,EAAEF,OAAO,CAACC,WAAW,CAAC;IACtE,IAAI,CAACE,UAAU,GAAGH,OAAO,CAACG,UAAU;EACtC;EAEA,IAAWC,WAAWA,CAAA,EAAW;IAC/B,OAAO,IAAI,CAACJ,OAAO,CAACI,WAAW;EACjC;EAEA,IAAWC,KAAKA,CAAA,EAAiB;IAC/B,OAAO,IAAI,CAACL,OAAO,CAACK,KAAK;EAC3B;EAEAC,gBAAgBA,CAAA,EAAmB;IACjC,OAAO,IAAIC,uBAAc,CAAC,IAAI,EAAE,IAAI,CAACP,OAAO,CAACM,gBAAgB,CAAC,C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ACH;AACF;AAACG,OAAA,CAAA7C,OAAA,GAAAC,gBAAA","ignoreList":[]}
|
|
@@ -9,8 +9,8 @@ const pkg = require('react-native-audio-api/package.json');
|
|
|
9
9
|
const withDefaultOptions = options => {
|
|
10
10
|
return {
|
|
11
11
|
iosBackgroundMode: true,
|
|
12
|
+
androidPermissions: ['android.permission.FOREGROUND_SERVICE', 'android.permission.WAKE_LOCK'],
|
|
12
13
|
androidForegroundService: true,
|
|
13
|
-
androidFSPermissions: ['android.permission.FOREGROUND_SERVICE', 'android.permission.WAKE_LOCK'],
|
|
14
14
|
androidFSTypes: ['mediaPlayback'],
|
|
15
15
|
...options
|
|
16
16
|
};
|
|
@@ -22,9 +22,9 @@ const withBackgroundAudio = config => {
|
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
24
|
const withAndroidPermissions = (config, {
|
|
25
|
-
|
|
25
|
+
androidPermissions
|
|
26
26
|
}) => {
|
|
27
|
-
return _configPlugins.AndroidConfig.Permissions.withPermissions(config,
|
|
27
|
+
return _configPlugins.AndroidConfig.Permissions.withPermissions(config, androidPermissions);
|
|
28
28
|
};
|
|
29
29
|
const withForegroundService = (config, {
|
|
30
30
|
androidFSTypes
|
|
@@ -53,8 +53,8 @@ const withAudioAPI = (config, optionsIn) => {
|
|
|
53
53
|
if (options.iosBackgroundMode) {
|
|
54
54
|
config = withBackgroundAudio(config);
|
|
55
55
|
}
|
|
56
|
+
config = withAndroidPermissions(config, options);
|
|
56
57
|
if (options.androidForegroundService) {
|
|
57
|
-
config = withAndroidPermissions(config, options);
|
|
58
58
|
config = withForegroundService(config, options);
|
|
59
59
|
}
|
|
60
60
|
return config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_configPlugins","require","pkg","withDefaultOptions","options","iosBackgroundMode","
|
|
1
|
+
{"version":3,"names":["_configPlugins","require","pkg","withDefaultOptions","options","iosBackgroundMode","androidPermissions","androidForegroundService","androidFSTypes","withBackgroundAudio","config","withInfoPlist","iosConfig","modResults","UIBackgroundModes","Array","from","Set","withAndroidPermissions","AndroidConfig","Permissions","withPermissions","withForegroundService","withAndroidManifest","mod","manifest","mainApplication","Manifest","getMainApplicationOrThrow","SFTypes","join","serviceElement","$","intentFilter","service","push","withAudioAPI","optionsIn","_default","exports","default","createRunOncePlugin","name","version"],"sourceRoot":"../../../src","sources":["plugin/withAudioAPI.ts"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAOA,MAAMC,GAAG,GAAGD,OAAO,CAAC,qCAAqC,CAAC;AAS1D,MAAME,kBAAkB,GAAIC,OAAyB,IAAc;EACjE,OAAO;IACLC,iBAAiB,EAAE,IAAI;IACvBC,kBAAkB,EAAE,CAClB,uCAAuC,EACvC,8BAA8B,CAC/B;IACDC,wBAAwB,EAAE,IAAI;IAC9BC,cAAc,EAAE,CAAC,eAAe,CAAC;IACjC,GAAGJ;EACL,CAAC;AACH,CAAC;AAED,MAAMK,mBAAiC,GAAIC,MAAM,IAAK;EACpD,OAAO,IAAAC,4BAAa,EAACD,MAAM,EAAGE,SAAS,IAAK;IAC1CA,SAAS,CAACC,UAAU,CAACC,iBAAiB,GAAG,CACvC,GAAGC,KAAK,CAACC,IAAI,CACX,IAAIC,GAAG,CAAC,CAAC,IAAIL,SAAS,CAACC,UAAU,CAACC,iBAAiB,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CACtE,CAAC,CACF;IAED,OAAOF,SAAS;EAClB,CAAC,CAAC;AACJ,CAAC;AAED,MAAMM,sBAA6C,GAAGA,CACpDR,MAAM,EACN;EAAEJ;AAA4B,CAAC,KAC5B;EACH,OAAOa,4BAAa,CAACC,WAAW,CAACC,eAAe,CAACX,MAAM,EAAEJ,kBAAkB,CAAC;AAC9E,CAAC;AAED,MAAMgB,qBAA4C,GAAGA,CACnDZ,MAAM,EACN;EAAEF;AAAwB,CAAC,KACxB;EACH,OAAO,IAAAe,kCAAmB,EAACb,MAAM,EAAGc,GAAG,IAAK;IAC1C,MAAMC,QAAQ,GAAGD,GAAG,CAACX,UAAU;IAC/B,MAAMa,eAAe,GACnBP,4BAAa,CAACQ,QAAQ,CAACC,yBAAyB,CAACH,QAAQ,CAAC;IAE5D,MAAMI,OAAO,GAAGrB,cAAc,CAACsB,IAAI,CAAC,GAAG,CAAC;IAExC,MAAMC,cAAc,GAAG;MACrBC,CAAC,EAAE;QACD,cAAc,EACZ,4EAA4E;QAC9E,sBAAsB,EAAE,MAAM;QAC9B,+BAA+B,EAAEH;MACnC,CAAC;MACDI,YAAY,EAAE;IAChB,CAAC;IAED,IAAI,CAACP,eAAe,CAACQ,OAAO,EAAE;MAC5BR,eAAe,CAACQ,OAAO,GAAG,EAAE;IAC9B;IAEAR,eAAe,CAACQ,OAAO,CAACC,IAAI,CAACJ,cAAc,CAAC;IAE5C,OAAOP,GAAG;EACZ,CAAC,CAAC;AACJ,CAAC;AAED,MAAMY,YAAmC,GAAGA,CAAC1B,MAAM,EAAE2B,SAAS,KAAK;EACjE,MAAMjC,OAAO,GAAGD,kBAAkB,CAACkC,SAAS,IAAI,CAAC,CAAC,CAAC;EAEnD,IAAIjC,OAAO,CAACC,iBAAiB,EAAE;IAC7BK,MAAM,GAAGD,mBAAmB,CAACC,MAAM,CAAC;EACtC;EAEAA,MAAM,GAAGQ,sBAAsB,CAACR,MAAM,EAAEN,OAAO,CAAC;EAEhD,IAAIA,OAAO,CAACG,wBAAwB,EAAE;IACpCG,MAAM,GAAGY,qBAAqB,CAACZ,MAAM,EAAEN,OAAO,CAAC;EACjD;EAEA,OAAOM,MAAM;AACf,CAAC;AAAC,IAAA4B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,kCAAmB,EAACL,YAAY,EAAElC,GAAG,CAACwC,IAAI,EAAExC,GAAG,CAACyC,OAAO,CAAC","ignoreList":[]}
|
|
@@ -71,8 +71,14 @@ export default class BaseAudioContext {
|
|
|
71
71
|
}
|
|
72
72
|
return new AudioBuffer(await this.context.decodeAudioDataSource(sourcePath));
|
|
73
73
|
}
|
|
74
|
-
async decodeAudioData(
|
|
75
|
-
|
|
74
|
+
async decodeAudioData(data) {
|
|
75
|
+
// pcm data in base64
|
|
76
|
+
if (typeof data === 'string') {
|
|
77
|
+
return new AudioBuffer(await this.context.decodePCMAudioDataInBase64(data));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// data in array buffer
|
|
81
|
+
return new AudioBuffer(await this.context.decodeAudioData(new Uint8Array(data)));
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
//# sourceMappingURL=BaseAudioContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AudioDestinationNode","OscillatorNode","GainNode","StereoPannerNode","BiquadFilterNode","AudioBufferSourceNode","AudioBuffer","PeriodicWave","AnalyserNode","AudioBufferQueueSourceNode","InvalidAccessError","NotSupportedError","BaseAudioContext","constructor","context","destination","sampleRate","currentTime","state","createOscillator","createGain","createStereoPanner","createBiquadFilter","createBufferSource","options","pitchCorrection","createBufferQueueSource","createBuffer","numOfChannels","length","createPeriodicWave","real","imag","constraints","disableNormalization","createAnalyser","decodeAudioDataSource","sourcePath","startsWith","replace","decodeAudioData","
|
|
1
|
+
{"version":3,"names":["AudioDestinationNode","OscillatorNode","GainNode","StereoPannerNode","BiquadFilterNode","AudioBufferSourceNode","AudioBuffer","PeriodicWave","AnalyserNode","AudioBufferQueueSourceNode","InvalidAccessError","NotSupportedError","BaseAudioContext","constructor","context","destination","sampleRate","currentTime","state","createOscillator","createGain","createStereoPanner","createBiquadFilter","createBufferSource","options","pitchCorrection","createBufferQueueSource","createBuffer","numOfChannels","length","createPeriodicWave","real","imag","constraints","disableNormalization","createAnalyser","decodeAudioDataSource","sourcePath","startsWith","replace","decodeAudioData","data","decodePCMAudioDataInBase64","Uint8Array"],"sourceRoot":"../../../src","sources":["core/BaseAudioContext.ts"],"mappings":";;AAMA,OAAOA,oBAAoB,MAAM,2BAAwB;AACzD,OAAOC,cAAc,MAAM,qBAAk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AEvE,OAAO,IAAI3B,YAAY,CACrB,IAAI,CAACO,OAAO,CAACgB,kBAAkB,CAACC,IAAI,EAAEC,IAAI,EAAEE,oBAAoB,CAClE,CAAC;EACH;EAEAC,cAAcA,CAAA,EAAiB;IAC7B,OAAO,IAAI3B,YAAY,CAAC,IAAI,EAAE,IAAI,CAACM,OAAO,CAACqB,cAAc,CAAC,CAAC,CAAC;EAC9D;EAEA,MAAMC,qBAAqBA,CAACC,UAAkB,EAAwB;IACpE;IACA,IAAIA,UAAU,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE;MACpCD,UAAU,GAAGA,UAAU,CAACE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;IAChD;IAEA,OAAO,IAAIjC,WAAW,CACpB,MAAM,IAAI,CAACQ,OAAO,CAACsB,qBAAqB,CAACC,UAAU,CACrD,CAAC;EACH;EAEA,MAAMG,eAAeA,CAACC,IAA0B,EAAwB;IACtE;IACA,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC5B,OAAO,IAAInC,WAAW,CACpB,MAAM,IAAI,CAACQ,OAAO,CAAC4B,0BAA0B,CAACD,IAAI,CACpD,CAAC;IACH;;IAEA;IACA,OAAO,IAAInC,WAAW,CACpB,MAAM,IAAI,CAACQ,OAAO,CAAC0B,eAAe,CAAC,IAAIG,UAAU,CAACF,IAAI,CAAC,CACzD,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -5,8 +5,8 @@ const pkg = require('react-native-audio-api/package.json');
|
|
|
5
5
|
const withDefaultOptions = options => {
|
|
6
6
|
return {
|
|
7
7
|
iosBackgroundMode: true,
|
|
8
|
+
androidPermissions: ['android.permission.FOREGROUND_SERVICE', 'android.permission.WAKE_LOCK'],
|
|
8
9
|
androidForegroundService: true,
|
|
9
|
-
androidFSPermissions: ['android.permission.FOREGROUND_SERVICE', 'android.permission.WAKE_LOCK'],
|
|
10
10
|
androidFSTypes: ['mediaPlayback'],
|
|
11
11
|
...options
|
|
12
12
|
};
|
|
@@ -18,9 +18,9 @@ const withBackgroundAudio = config => {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
const withAndroidPermissions = (config, {
|
|
21
|
-
|
|
21
|
+
androidPermissions
|
|
22
22
|
}) => {
|
|
23
|
-
return AndroidConfig.Permissions.withPermissions(config,
|
|
23
|
+
return AndroidConfig.Permissions.withPermissions(config, androidPermissions);
|
|
24
24
|
};
|
|
25
25
|
const withForegroundService = (config, {
|
|
26
26
|
androidFSTypes
|
|
@@ -49,8 +49,8 @@ const withAudioAPI = (config, optionsIn) => {
|
|
|
49
49
|
if (options.iosBackgroundMode) {
|
|
50
50
|
config = withBackgroundAudio(config);
|
|
51
51
|
}
|
|
52
|
+
config = withAndroidPermissions(config, options);
|
|
52
53
|
if (options.androidForegroundService) {
|
|
53
|
-
config = withAndroidPermissions(config, options);
|
|
54
54
|
config = withForegroundService(config, options);
|
|
55
55
|
}
|
|
56
56
|
return config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AndroidConfig","createRunOncePlugin","withInfoPlist","withAndroidManifest","pkg","require","withDefaultOptions","options","iosBackgroundMode","
|
|
1
|
+
{"version":3,"names":["AndroidConfig","createRunOncePlugin","withInfoPlist","withAndroidManifest","pkg","require","withDefaultOptions","options","iosBackgroundMode","androidPermissions","androidForegroundService","androidFSTypes","withBackgroundAudio","config","iosConfig","modResults","UIBackgroundModes","Array","from","Set","withAndroidPermissions","Permissions","withPermissions","withForegroundService","mod","manifest","mainApplication","Manifest","getMainApplicationOrThrow","SFTypes","join","serviceElement","$","intentFilter","service","push","withAudioAPI","optionsIn","name","version"],"sourceRoot":"../../../src","sources":["plugin/withAudioAPI.ts"],"mappings":";;AAAA,SACEA,aAAa,EACbC,mBAAmB,EAEnBC,aAAa,EACbC,mBAAmB,QACd,sBAAsB;AAC7B,MAAMC,GAAG,GAAGC,OAAO,CAAC,qCAAqC,CAAC;AAS1D,MAAMC,kBAAkB,GAAIC,OAAyB,IAAc;EAC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R,eAAe,CAACQ,OAAO,GAAG,EAAE;IAC9B;IAEAR,eAAe,CAACQ,OAAO,CAACC,IAAI,CAACJ,cAAc,CAAC;IAE5C,OAAOP,GAAG;EACZ,CAAC,CAAC;AACJ,CAAC;AAED,MAAMY,YAAmC,GAAGA,CAACvB,MAAM,EAAEwB,SAAS,KAAK;EACjE,MAAM9B,OAAO,GAAGD,kBAAkB,CAAC+B,SAAS,IAAI,CAAC,CAAC,CAAC;EAEnD,IAAI9B,OAAO,CAACC,iBAAiB,EAAE;IAC7BK,MAAM,GAAGD,mBAAmB,CAACC,MAAM,CAAC;EACtC;EAEAA,MAAM,GAAGO,sBAAsB,CAACP,MAAM,EAAEN,OAAO,CAAC;EAEhD,IAAIA,OAAO,CAACG,wBAAwB,EAAE;IACpCG,MAAM,GAAGU,qBAAqB,CAACV,MAAM,EAAEN,OAAO,CAAC;EACjD;EAEA,OAAOM,MAAM;AACf,CAAC;AAED,eAAeZ,mBAAmB,CAACmC,YAAY,EAAEhC,GAAG,CAACkC,IAAI,EAAElC,GAAG,CAACmC,OAAO,CAAC","ignoreList":[]}
|
|
@@ -27,6 +27,6 @@ export default class BaseAudioContext {
|
|
|
27
27
|
createPeriodicWave(real: Float32Array, imag: Float32Array, constraints?: PeriodicWaveConstraints): PeriodicWave;
|
|
28
28
|
createAnalyser(): AnalyserNode;
|
|
29
29
|
decodeAudioDataSource(sourcePath: string): Promise<AudioBuffer>;
|
|
30
|
-
decodeAudioData(
|
|
30
|
+
decodeAudioData(data: ArrayBuffer | string): Promise<AudioBuffer>;
|
|
31
31
|
}
|
|
32
32
|
//# sourceMappingURL=BaseAudioContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseAudioContext.d.ts","sourceRoot":"","sources":["../../../src/core/BaseAudioContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,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CAChB,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,YAAY,EAClB,WAAW,CAAC,EAAE,uBAAuB,GACpC,YAAY;IAcf,cAAc,IAAI,YAAY;IAIxB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAW/D,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAaxE"}
|
|
@@ -16,6 +16,7 @@ export interface IBaseAudioContext {
|
|
|
16
16
|
createAnalyser: () => IAnalyserNode;
|
|
17
17
|
decodeAudioDataSource: (sourcePath: string) => Promise<IAudioBuffer>;
|
|
18
18
|
decodeAudioData: (arrayBuffer: ArrayBuffer) => Promise<IAudioBuffer>;
|
|
19
|
+
decodePCMAudioDataInBase64: (b64: string) => Promise<IAudioBuffer>;
|
|
19
20
|
}
|
|
20
21
|
export interface IAudioContext extends IBaseAudioContext {
|
|
21
22
|
close(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,gBAAgB,IAAI,eAAe,CAAC;IACpC,UAAU,IAAI,SAAS,CAAC;IACxB,kBAAkB,IAAI,iBAAiB,CAAC;IACxC,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;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IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IAGjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,qBAAqB,CAAC,IAAI,SAAS,cAAc,EAC/C,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC,GACjC,MAAM,CAAC;IACV,wBAAwB,CAAC,IAAI,SAAS,cAAc,EAClD,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,MAAM,GACrB,IAAI,CAAC;CACT"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConfigPlugin } from '@expo/config-plugins';
|
|
2
2
|
interface Options {
|
|
3
3
|
iosBackgroundMode: boolean;
|
|
4
|
+
androidPermissions: string[];
|
|
4
5
|
androidForegroundService: boolean;
|
|
5
|
-
androidFSPermissions: string[];
|
|
6
6
|
androidFSTypes: string[];
|
|
7
7
|
}
|
|
8
8
|
declare const _default: ConfigPlugin<Options>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withAudioAPI.d.ts","sourceRoot":"","sources":["../../../src/plugin/withAudioAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAG9B,UAAU,OAAO;IACf,iBAAiB,EAAE,OAAO,CAAC;IAC3B,
|
|
1
|
+
{"version":3,"file":"withAudioAPI.d.ts","sourceRoot":"","sources":["../../../src/plugin/withAudioAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAGb,MAAM,sBAAsB,CAAC;AAG9B,UAAU,OAAO;IACf,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,wBAAwB,EAAE,OAAO,CAAC;IAClC,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;;AAiFD,wBAAwE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-audio-api",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2-rc.0",
|
|
4
4
|
"description": "react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification",
|
|
5
5
|
"bin": {
|
|
6
6
|
"setup-rn-audio-api-web": "./scripts/setup-rn-audio-api-web.js"
|
|
@@ -130,9 +130,17 @@ export default class BaseAudioContext {
|
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
async decodeAudioData(
|
|
133
|
+
async decodeAudioData(data: ArrayBuffer | string): Promise<AudioBuffer> {
|
|
134
|
+
// pcm data in base64
|
|
135
|
+
if (typeof data === 'string') {
|
|
136
|
+
return new AudioBuffer(
|
|
137
|
+
await this.context.decodePCMAudioDataInBase64(data)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// data in array buffer
|
|
134
142
|
return new AudioBuffer(
|
|
135
|
-
await this.context.decodeAudioData(new Uint8Array(
|
|
143
|
+
await this.context.decodeAudioData(new Uint8Array(data))
|
|
136
144
|
);
|
|
137
145
|
}
|
|
138
146
|
}
|
package/src/interfaces.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface IBaseAudioContext {
|
|
|
33
33
|
createAnalyser: () => IAnalyserNode;
|
|
34
34
|
decodeAudioDataSource: (sourcePath: string) => Promise<IAudioBuffer>;
|
|
35
35
|
decodeAudioData: (arrayBuffer: ArrayBuffer) => Promise<IAudioBuffer>;
|
|
36
|
+
decodePCMAudioDataInBase64: (b64: string) => Promise<IAudioBuffer>;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export interface IAudioContext extends IBaseAudioContext {
|
|
@@ -9,19 +9,19 @@ const pkg = require('react-native-audio-api/package.json');
|
|
|
9
9
|
|
|
10
10
|
interface Options {
|
|
11
11
|
iosBackgroundMode: boolean;
|
|
12
|
+
androidPermissions: string[];
|
|
12
13
|
androidForegroundService: boolean;
|
|
13
|
-
androidFSPermissions: string[];
|
|
14
14
|
androidFSTypes: string[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const withDefaultOptions = (options: Partial<Options>): Options => {
|
|
18
18
|
return {
|
|
19
19
|
iosBackgroundMode: true,
|
|
20
|
-
|
|
21
|
-
androidFSPermissions: [
|
|
20
|
+
androidPermissions: [
|
|
22
21
|
'android.permission.FOREGROUND_SERVICE',
|
|
23
22
|
'android.permission.WAKE_LOCK',
|
|
24
23
|
],
|
|
24
|
+
androidForegroundService: true,
|
|
25
25
|
androidFSTypes: ['mediaPlayback'],
|
|
26
26
|
...options,
|
|
27
27
|
};
|
|
@@ -41,12 +41,9 @@ const withBackgroundAudio: ConfigPlugin = (config) => {
|
|
|
41
41
|
|
|
42
42
|
const withAndroidPermissions: ConfigPlugin<Options> = (
|
|
43
43
|
config,
|
|
44
|
-
{
|
|
44
|
+
{ androidPermissions }: Options
|
|
45
45
|
) => {
|
|
46
|
-
return AndroidConfig.Permissions.withPermissions(
|
|
47
|
-
config,
|
|
48
|
-
androidFSPermissions
|
|
49
|
-
);
|
|
46
|
+
return AndroidConfig.Permissions.withPermissions(config, androidPermissions);
|
|
50
47
|
};
|
|
51
48
|
|
|
52
49
|
const withForegroundService: ConfigPlugin<Options> = (
|
|
@@ -87,8 +84,9 @@ const withAudioAPI: ConfigPlugin<Options> = (config, optionsIn) => {
|
|
|
87
84
|
config = withBackgroundAudio(config);
|
|
88
85
|
}
|
|
89
86
|
|
|
87
|
+
config = withAndroidPermissions(config, options);
|
|
88
|
+
|
|
90
89
|
if (options.androidForegroundService) {
|
|
91
|
-
config = withAndroidPermissions(config, options);
|
|
92
90
|
config = withForegroundService(config, options);
|
|
93
91
|
}
|
|
94
92
|
|