react-native-audio-api 0.6.0-rc.4 → 0.6.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/AudioAPIModule.cpp +35 -2
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +4 -0
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +31 -17
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +1 -3
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +56 -2
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIPackage.kt +0 -12
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +35 -12
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +30 -29
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +20 -22
- package/android/src/main/java/com/swmansion/audioapi/system/MediaReceiver.kt +19 -9
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionCallback.kt +30 -11
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +53 -26
- package/android/src/main/java/com/swmansion/audioapi/system/VolumeChangeListener.kt +10 -5
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +39 -0
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +20 -14
- package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +2 -3
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +24 -11
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +1 -0
- package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +10 -89
- package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +3 -24
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +2 -2
- package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +2 -3
- package/common/cpp/audioapi/core/AudioContext.cpp +4 -1
- package/common/cpp/audioapi/core/AudioContext.h +1 -1
- package/common/cpp/audioapi/core/AudioNode.cpp +31 -2
- package/common/cpp/audioapi/core/AudioNode.h +7 -1
- package/common/cpp/audioapi/core/AudioParam.cpp +84 -2
- package/common/cpp/audioapi/core/AudioParam.h +14 -1
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +7 -1
- package/common/cpp/audioapi/core/BaseAudioContext.h +7 -1
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +3 -2
- package/common/cpp/audioapi/core/OfflineAudioContext.h +1 -1
- package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +19 -56
- package/common/cpp/audioapi/core/analysis/AnalyserNode.h +3 -2
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +28 -26
- package/common/cpp/audioapi/core/effects/GainNode.cpp +9 -9
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +5 -2
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +56 -0
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +13 -13
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +14 -10
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +1 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +7 -6
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +5 -3
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +15 -10
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +35 -1
- package/common/cpp/audioapi/core/utils/AudioNodeManager.h +15 -1
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +108 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +62 -0
- package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +48 -0
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +3 -4
- package/common/cpp/audioapi/utils/AudioArray.h +1 -1
- package/common/cpp/audioapi/utils/CircularAudioArray.cpp +94 -0
- package/common/cpp/audioapi/utils/CircularAudioArray.h +26 -0
- package/ios/audioapi/ios/AudioAPIModule.h +13 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +115 -6
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +3 -10
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +15 -52
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +2 -0
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +7 -3
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +7 -0
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +12 -0
- package/ios/audioapi/ios/system/AudioEngine.h +5 -0
- package/ios/audioapi/ios/system/AudioEngine.mm +7 -15
- package/ios/audioapi/ios/system/AudioSessionManager.h +3 -1
- package/ios/audioapi/ios/system/AudioSessionManager.mm +36 -17
- package/ios/audioapi/ios/system/LockScreenManager.h +3 -3
- package/ios/audioapi/ios/system/LockScreenManager.mm +36 -48
- package/ios/audioapi/ios/system/NotificationManager.h +3 -3
- package/ios/audioapi/ios/system/NotificationManager.mm +21 -29
- package/lib/commonjs/api.js +4 -4
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioBufferSourceNode.js +2 -2
- package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioNode.js +8 -2
- package/lib/commonjs/core/AudioNode.js.map +1 -1
- package/lib/commonjs/core/AudioParam.js +2 -1
- package/lib/commonjs/core/AudioParam.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +11 -28
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/commonjs/core/BiquadFilterNode.js +4 -4
- package/lib/commonjs/core/BiquadFilterNode.js.map +1 -1
- package/lib/commonjs/core/GainNode.js +1 -1
- package/lib/commonjs/core/GainNode.js.map +1 -1
- package/lib/commonjs/core/OscillatorNode.js +2 -2
- package/lib/commonjs/core/OscillatorNode.js.map +1 -1
- package/lib/commonjs/core/StereoPannerNode.js +1 -1
- package/lib/commonjs/core/StereoPannerNode.js.map +1 -1
- package/lib/commonjs/events/AudioEventEmitter.js +22 -0
- package/lib/commonjs/events/AudioEventEmitter.js.map +1 -0
- package/lib/commonjs/events/AudioEventSubscription.js +20 -0
- package/lib/commonjs/events/AudioEventSubscription.js.map +1 -0
- package/lib/commonjs/events/index.js +21 -0
- package/lib/commonjs/events/index.js.map +1 -0
- package/lib/commonjs/events/types.js +6 -0
- package/lib/commonjs/events/types.js.map +1 -0
- package/lib/commonjs/hooks/useSytemVolume.js +1 -1
- package/lib/commonjs/hooks/useSytemVolume.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js +3 -3
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/specs/index.js +2 -16
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +26 -26
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/module/api.js +2 -2
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioBufferSourceNode.js +2 -2
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/core/AudioNode.js +7 -2
- package/lib/module/core/AudioNode.js.map +1 -1
- package/lib/module/core/AudioParam.js +2 -1
- package/lib/module/core/AudioParam.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +11 -28
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/AudioScheduledSourceNode.js +4 -1
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/module/core/BiquadFilterNode.js +4 -4
- package/lib/module/core/BiquadFilterNode.js.map +1 -1
- package/lib/module/core/GainNode.js +1 -1
- package/lib/module/core/GainNode.js.map +1 -1
- package/lib/module/core/OscillatorNode.js +2 -2
- package/lib/module/core/OscillatorNode.js.map +1 -1
- package/lib/module/core/StereoPannerNode.js +1 -1
- package/lib/module/core/StereoPannerNode.js.map +1 -1
- package/lib/module/events/AudioEventEmitter.js +16 -0
- package/lib/module/events/AudioEventEmitter.js.map +1 -0
- package/lib/module/events/AudioEventSubscription.js +15 -0
- package/lib/module/events/AudioEventSubscription.js.map +1 -0
- package/lib/module/events/index.js +6 -0
- package/lib/module/events/index.js.map +1 -0
- package/lib/module/events/types.js +4 -0
- package/lib/module/events/types.js.map +1 -0
- package/lib/module/hooks/useSytemVolume.js +1 -1
- package/lib/module/hooks/useSytemVolume.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js +3 -2
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/specs/index.js +2 -3
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/system/AudioManager.js +27 -27
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/typescript/api.d.ts +2 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioNode.d.ts +2 -1
- package/lib/typescript/core/AudioNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioParam.d.ts +4 -2
- package/lib/typescript/core/AudioParam.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +4 -14
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +3 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts.map +1 -1
- package/lib/typescript/events/AudioEventEmitter.d.ts +10 -0
- package/lib/typescript/events/AudioEventEmitter.d.ts.map +1 -0
- package/lib/typescript/events/AudioEventSubscription.d.ts +11 -0
- package/lib/typescript/events/AudioEventSubscription.d.ts.map +1 -0
- package/lib/typescript/events/index.d.ts +4 -0
- package/lib/typescript/events/index.d.ts.map +1 -0
- package/lib/typescript/events/types.d.ts +50 -0
- package/lib/typescript/events/types.d.ts.map +1 -0
- package/lib/typescript/hooks/useSytemVolume.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +10 -10
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +15 -3
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/specs/index.d.ts +2 -3
- package/lib/typescript/specs/index.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +8 -4
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/system/types.d.ts +1 -34
- package/lib/typescript/system/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +0 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +6 -3
- package/src/core/AudioBufferSourceNode.ts +2 -2
- package/src/core/AudioNode.ts +8 -3
- package/src/core/AudioParam.ts +5 -2
- package/src/core/AudioRecorder.ts +22 -62
- package/src/core/AudioScheduledSourceNode.ts +13 -2
- package/src/core/BiquadFilterNode.ts +4 -4
- package/src/core/GainNode.ts +1 -1
- package/src/core/OscillatorNode.ts +2 -2
- package/src/core/StereoPannerNode.ts +1 -1
- package/src/events/AudioEventEmitter.ts +29 -0
- package/src/events/AudioEventSubscription.ts +26 -0
- package/src/events/index.ts +4 -0
- package/src/events/types.ts +64 -0
- package/src/hooks/useSytemVolume.ts +2 -1
- package/src/interfaces.ts +19 -20
- package/src/specs/NativeAudioAPIModule.ts +23 -2
- package/src/specs/index.ts +2 -4
- package/src/system/AudioManager.ts +39 -38
- package/src/system/types.ts +1 -41
- package/src/types.ts +0 -8
- package/android/src/main/java/com/swmansion/audioapi/AudioManagerModule.kt +0 -64
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionEventEmitter.kt +0 -88
- package/android/src/oldarch/NativeAudioManagerModuleSpec.java +0 -99
- package/ios/audioapi/ios/AudioManagerModule.h +0 -18
- package/ios/audioapi/ios/AudioManagerModule.mm +0 -93
- package/lib/commonjs/specs/NativeAudioManagerModule.js +0 -36
- package/lib/commonjs/specs/NativeAudioManagerModule.js.map +0 -1
- package/lib/module/specs/NativeAudioManagerModule.js +0 -33
- package/lib/module/specs/NativeAudioManagerModule.js.map +0 -1
- package/lib/typescript/specs/NativeAudioManagerModule.d.ts +0 -15
- package/lib/typescript/specs/NativeAudioManagerModule.d.ts.map +0 -1
- package/src/specs/NativeAudioManagerModule.ts +0 -45
|
@@ -2,73 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
#include <audioapi/core/Constants.h>
|
|
4
4
|
#include <audioapi/dsp/VectorMath.h>
|
|
5
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
5
6
|
#include <audioapi/ios/core/IOSAudioRecorder.h>
|
|
6
7
|
#include <audioapi/utils/AudioArray.h>
|
|
7
8
|
#include <audioapi/utils/AudioBus.h>
|
|
9
|
+
#include <audioapi/utils/CircularAudioArray.h>
|
|
10
|
+
#include <unordered_map>
|
|
8
11
|
|
|
9
12
|
namespace audioapi {
|
|
10
13
|
|
|
11
14
|
IOSAudioRecorder::IOSAudioRecorder(
|
|
12
15
|
float sampleRate,
|
|
13
16
|
int bufferLength,
|
|
14
|
-
const std::
|
|
15
|
-
|
|
16
|
-
const std::function<void(std::shared_ptr<AudioBus>, int, double)> &onAudioReady)
|
|
17
|
-
: AudioRecorder(sampleRate, bufferLength, onError, onStatusChange, onAudioReady)
|
|
17
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
|
|
18
|
+
: AudioRecorder(sampleRate, bufferLength, audioEventHandlerRegistry)
|
|
18
19
|
{
|
|
19
|
-
circularBuffer_ = std::make_shared<AudioBus>(std::max(2 * bufferLength, 2048), 1, sampleRate);
|
|
20
|
-
|
|
21
20
|
AudioReceiverBlock audioReceiverBlock = ^(const AudioBufferList *inputBuffer, int numFrames, AVAudioTime *when) {
|
|
22
21
|
if (isRunning_.load()) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
auto framesToProcess = numFrames;
|
|
28
|
-
auto framesToCopy = 0;
|
|
29
|
-
|
|
30
|
-
if (writeIdx_ + numFrames > circularBuffer_->getSize()) {
|
|
31
|
-
framesToCopy = circularBuffer_->getSize() - writeIdx_;
|
|
32
|
-
memcpy(circularBufferChannel + writeIdx_, inputChannel, framesToCopy * sizeof(float));
|
|
33
|
-
framesToProcess -= framesToCopy;
|
|
34
|
-
writeIdx_ = 0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
memcpy(circularBufferChannel + writeIdx_, inputChannel + framesToCopy, framesToProcess * sizeof(float));
|
|
38
|
-
|
|
39
|
-
writeIdx_ += framesToProcess;
|
|
40
|
-
if (writeIdx_ >= circularBuffer_->getSize()) {
|
|
41
|
-
writeIdx_ = 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// copying to output bus and invoking callback
|
|
45
|
-
auto availableFrames =
|
|
46
|
-
writeIdx_ >= readIdx_ ? writeIdx_ - readIdx_ : circularBuffer_->getSize() - (readIdx_ - writeIdx_);
|
|
47
|
-
|
|
48
|
-
while (availableFrames >= bufferLength_) {
|
|
49
|
-
auto bus = std::make_shared<AudioBus>(bufferLength_, 1, sampleRate_);
|
|
50
|
-
auto *outputChannel = bus->getChannel(0)->getData();
|
|
51
|
-
|
|
52
|
-
framesToProcess = bufferLength_;
|
|
53
|
-
framesToCopy = 0;
|
|
54
|
-
if (readIdx_ + bufferLength_ > circularBuffer_->getSize()) {
|
|
55
|
-
framesToCopy = circularBuffer_->getSize() - readIdx_;
|
|
56
|
-
memcpy(outputChannel, circularBufferChannel + readIdx_, framesToCopy * sizeof(float));
|
|
57
|
-
framesToProcess -= framesToCopy;
|
|
58
|
-
readIdx_ = 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
memcpy(outputChannel + framesToCopy, circularBufferChannel + readIdx_, framesToProcess * sizeof(float));
|
|
22
|
+
auto *inputChannel = static_cast<float *>(inputBuffer->mBuffers[0].mData);
|
|
23
|
+
circularBuffer_->push_back(inputChannel, numFrames);
|
|
24
|
+
}
|
|
62
25
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
26
|
+
while (circularBuffer_->getNumberOfAvailableFrames() >= bufferLength_) {
|
|
27
|
+
auto bus = std::make_shared<AudioBus>(bufferLength_, 1, sampleRate_);
|
|
28
|
+
auto *outputChannel = bus->getChannel(0)->getData();
|
|
67
29
|
|
|
68
|
-
|
|
30
|
+
circularBuffer_->pop_front(outputChannel, bufferLength_);
|
|
69
31
|
|
|
70
|
-
|
|
71
|
-
}
|
|
32
|
+
invokeOnAudioReadyCallback(bus, bufferLength_, [when sampleTime] / [when sampleRate]);
|
|
72
33
|
}
|
|
73
34
|
};
|
|
74
35
|
|
|
@@ -103,6 +64,8 @@ void IOSAudioRecorder::stop()
|
|
|
103
64
|
|
|
104
65
|
isRunning_.store(false);
|
|
105
66
|
[audioRecorder_ stop];
|
|
67
|
+
|
|
68
|
+
sendRemainingData();
|
|
106
69
|
}
|
|
107
70
|
|
|
108
71
|
} // namespace audioapi
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
NSLog(@"[AudioPlayer] start");
|
|
38
38
|
|
|
39
39
|
AudioEngine *audioEngine = [AudioEngine sharedInstance];
|
|
40
|
+
assert(audioEngine != nil);
|
|
40
41
|
self.sourceNodeId = [audioEngine attachSourceNode:self.sourceNode format:self.format];
|
|
41
42
|
}
|
|
42
43
|
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
NSLog(@"[AudioPlayer] stop");
|
|
46
47
|
|
|
47
48
|
AudioEngine *audioEngine = [AudioEngine sharedInstance];
|
|
49
|
+
assert(audioEngine != nil);
|
|
48
50
|
[audioEngine detachSourceNodeWithId:self.sourceNodeId];
|
|
49
51
|
self.sourceNodeId = nil;
|
|
50
52
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
self.receiverBlock = [receiverBlock copy];
|
|
16
16
|
|
|
17
|
-
float devicePrefferedSampleRate = [[
|
|
17
|
+
float devicePrefferedSampleRate = [[AVAudioSession sharedInstance] sampleRate];
|
|
18
18
|
|
|
19
19
|
self.inputFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
|
|
20
20
|
sampleRate:devicePrefferedSampleRate
|
|
@@ -91,12 +91,16 @@
|
|
|
91
91
|
|
|
92
92
|
- (void)start
|
|
93
93
|
{
|
|
94
|
-
[
|
|
94
|
+
AudioEngine *audioEngine = [AudioEngine sharedInstance];
|
|
95
|
+
assert(audioEngine != nil);
|
|
96
|
+
[audioEngine attachInputNode:self.sinkNode];
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
- (void)stop
|
|
98
100
|
{
|
|
99
|
-
[
|
|
101
|
+
AudioEngine *audioEngine = [AudioEngine sharedInstance];
|
|
102
|
+
assert(audioEngine != nil);
|
|
103
|
+
[audioEngine detachInputNode];
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
- (void)cleanup
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// #import <audioapi/ios/events/IOSAudioEventHandlerRegistry.h>
|
|
2
|
+
//
|
|
3
|
+
// #include <memory>
|
|
4
|
+
// #include
|
|
5
|
+
//
|
|
6
|
+
//@implementation IOSAudioEventHandlerRegistry {
|
|
7
|
+
// std::shared_ptr<AudioEventHandlerRegistry> _eventHandler;
|
|
8
|
+
//
|
|
9
|
+
//
|
|
10
|
+
// }
|
|
11
|
+
//
|
|
12
|
+
//@end
|
|
@@ -3,12 +3,17 @@
|
|
|
3
3
|
#import <AVFoundation/AVFoundation.h>
|
|
4
4
|
#import <Foundation/Foundation.h>
|
|
5
5
|
|
|
6
|
+
@class AudioSessionManager;
|
|
7
|
+
|
|
6
8
|
@interface AudioEngine : NSObject
|
|
7
9
|
|
|
8
10
|
@property (nonatomic, strong) AVAudioEngine *audioEngine;
|
|
9
11
|
@property (nonatomic, strong) NSMutableDictionary *sourceNodes;
|
|
10
12
|
@property (nonatomic, strong) NSMutableDictionary *sourceFormats;
|
|
11
13
|
@property (nonatomic, strong) AVAudioSinkNode *inputNode;
|
|
14
|
+
@property (nonatomic, weak) AudioSessionManager *sessionManager;
|
|
15
|
+
|
|
16
|
+
- (instancetype)initWithAudioSessionManager:(AudioSessionManager *)sessionManager;
|
|
12
17
|
|
|
13
18
|
+ (instancetype)sharedInstance;
|
|
14
19
|
- (void)cleanup;
|
|
@@ -7,22 +7,10 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
7
7
|
|
|
8
8
|
+ (instancetype)sharedInstance
|
|
9
9
|
{
|
|
10
|
-
static dispatch_once_t onceToken;
|
|
11
|
-
|
|
12
|
-
dispatch_once(&onceToken, ^{
|
|
13
|
-
_sharedInstance = [[self alloc] initPrivate];
|
|
14
|
-
});
|
|
15
|
-
|
|
16
10
|
return _sharedInstance;
|
|
17
11
|
}
|
|
18
12
|
|
|
19
|
-
- (instancetype)
|
|
20
|
-
{
|
|
21
|
-
@throw [NSException exceptionWithName:@"Singleton" reason:@"Use +[AudioEngine sharedInstance]" userInfo:nil];
|
|
22
|
-
return nil;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
- (instancetype)initPrivate
|
|
13
|
+
- (instancetype)initWithAudioSessionManager:(AudioSessionManager *)sessionManager
|
|
26
14
|
{
|
|
27
15
|
if (self = [super init]) {
|
|
28
16
|
self.audioEngine = [[AVAudioEngine alloc] init];
|
|
@@ -31,9 +19,12 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
31
19
|
self.sourceNodes = [[NSMutableDictionary alloc] init];
|
|
32
20
|
self.sourceFormats = [[NSMutableDictionary alloc] init];
|
|
33
21
|
|
|
34
|
-
|
|
22
|
+
self.sessionManager = sessionManager;
|
|
23
|
+
[self.sessionManager setActive:true];
|
|
35
24
|
}
|
|
36
25
|
|
|
26
|
+
_sharedInstance = self;
|
|
27
|
+
|
|
37
28
|
return self;
|
|
38
29
|
}
|
|
39
30
|
|
|
@@ -49,7 +40,8 @@ static AudioEngine *_sharedInstance = nil;
|
|
|
49
40
|
self.sourceFormats = nil;
|
|
50
41
|
self.inputNode = nil;
|
|
51
42
|
|
|
52
|
-
[
|
|
43
|
+
[self.sessionManager setActive:false];
|
|
44
|
+
self.sessionManager = nil;
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
- (bool)rebuildAudioEngine
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
@property (nonatomic, assign) AVAudioSessionCategory sessionCategory;
|
|
14
14
|
@property (nonatomic, assign) AVAudioSessionCategoryOptions sessionOptions;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
- (instancetype)init;
|
|
17
17
|
- (void)cleanup;
|
|
18
18
|
- (bool)configureAudioSession;
|
|
19
19
|
|
|
20
20
|
- (NSNumber *)getDevicePreferredSampleRate;
|
|
21
21
|
- (void)setAudioSessionOptions:(NSString *)category mode:(NSString *)mode options:(NSArray *)options;
|
|
22
22
|
- (bool)setActive:(bool)active;
|
|
23
|
+
- (NSString *)requestRecordingPermissions;
|
|
24
|
+
- (NSString *)checkRecordingPermissions;
|
|
23
25
|
|
|
24
26
|
@end
|
|
@@ -2,24 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
@implementation AudioSessionManager
|
|
4
4
|
|
|
5
|
-
static AudioSessionManager *_sharedInstance = nil;
|
|
6
|
-
|
|
7
|
-
+ (instancetype)sharedInstance
|
|
8
|
-
{
|
|
9
|
-
static dispatch_once_t onceToken;
|
|
10
|
-
dispatch_once(&onceToken, ^{
|
|
11
|
-
_sharedInstance = [[self alloc] initPrivate];
|
|
12
|
-
});
|
|
13
|
-
return _sharedInstance;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
5
|
- (instancetype)init
|
|
17
|
-
{
|
|
18
|
-
@throw [NSException exceptionWithName:@"Singleton" reason:@"Use +[AudioSessionManager sharedInstance]" userInfo:nil];
|
|
19
|
-
return nil;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
- (instancetype)initPrivate
|
|
23
6
|
{
|
|
24
7
|
if (self = [super init]) {
|
|
25
8
|
self.audioSession = [AVAudioSession sharedInstance];
|
|
@@ -192,4 +175,40 @@ static AudioSessionManager *_sharedInstance = nil;
|
|
|
192
175
|
return true;
|
|
193
176
|
}
|
|
194
177
|
|
|
178
|
+
- (NSString *)requestRecordingPermissions
|
|
179
|
+
{
|
|
180
|
+
[self.audioSession requestRecordPermission:^(BOOL granted){
|
|
181
|
+
}];
|
|
182
|
+
return [self checkRecordingPermissions];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
- (NSString *)checkRecordingPermissions
|
|
186
|
+
{
|
|
187
|
+
if (@available(iOS 17, *)) {
|
|
188
|
+
NSInteger res = [[AVAudioApplication sharedInstance] recordPermission];
|
|
189
|
+
switch (res) {
|
|
190
|
+
case AVAudioApplicationRecordPermissionUndetermined:
|
|
191
|
+
return @"Undetermined";
|
|
192
|
+
case AVAudioApplicationRecordPermissionGranted:
|
|
193
|
+
return @"Granted";
|
|
194
|
+
case AVAudioApplicationRecordPermissionDenied:
|
|
195
|
+
return @"Denied";
|
|
196
|
+
default:
|
|
197
|
+
return @"Undetermined";
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
NSInteger res = [self.audioSession recordPermission];
|
|
201
|
+
switch (res) {
|
|
202
|
+
case AVAudioSessionRecordPermissionUndetermined:
|
|
203
|
+
return @"Undetermined";
|
|
204
|
+
case AVAudioSessionRecordPermissionGranted:
|
|
205
|
+
return @"Granted";
|
|
206
|
+
case AVAudioSessionRecordPermissionDenied:
|
|
207
|
+
return @"Denied";
|
|
208
|
+
default:
|
|
209
|
+
return @"Undetermined";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
195
214
|
@end
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
#import <Foundation/Foundation.h>
|
|
5
5
|
#import <MediaPlayer/MediaPlayer.h>
|
|
6
6
|
|
|
7
|
-
@class
|
|
7
|
+
@class AudioAPIModule;
|
|
8
8
|
|
|
9
9
|
@interface LockScreenManager : NSObject
|
|
10
10
|
|
|
11
|
-
@property (nonatomic, weak)
|
|
11
|
+
@property (nonatomic, weak) AudioAPIModule *audioAPIModule;
|
|
12
12
|
|
|
13
13
|
@property (nonatomic, weak) MPNowPlayingInfoCenter *playingInfoCenter;
|
|
14
14
|
@property (nonatomic, copy) NSString *artworkUrl;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
- (instancetype)initWithAudioAPIModule:(AudioAPIModule *)audioAPIModule;
|
|
17
17
|
- (void)cleanup;
|
|
18
18
|
|
|
19
19
|
- (void)setLockScreenInfo:(NSDictionary *)info;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#import <MediaPlayer/MediaPlayer.h>
|
|
2
|
-
#import <audioapi/ios/
|
|
2
|
+
#import <audioapi/ios/AudioAPIModule.h>
|
|
3
3
|
#import <audioapi/ios/system/LockScreenManager.h>
|
|
4
4
|
|
|
5
5
|
#define LOCK_SCREEN_INFO \
|
|
@@ -14,30 +14,14 @@
|
|
|
14
14
|
|
|
15
15
|
@implementation LockScreenManager
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
+ (instancetype)sharedInstanceWithAudioManagerModule:(AudioManagerModule *)audioManagerModule
|
|
20
|
-
{
|
|
21
|
-
static dispatch_once_t onceToken;
|
|
22
|
-
dispatch_once(&onceToken, ^{
|
|
23
|
-
_sharedInstance = [[self alloc] initPrivateWithAudioManagerModule:audioManagerModule];
|
|
24
|
-
});
|
|
25
|
-
return _sharedInstance;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
- (instancetype)init
|
|
29
|
-
{
|
|
30
|
-
@throw [NSException exceptionWithName:@"Singleton" reason:@"Use +[LockScreenManager sharedInstance]" userInfo:nil];
|
|
31
|
-
return nil;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
- (instancetype)initPrivateWithAudioManagerModule:(AudioManagerModule *)audioManagerModule
|
|
17
|
+
- (instancetype)initWithAudioAPIModule:(AudioAPIModule *)audioAPIModule
|
|
35
18
|
{
|
|
36
19
|
if (self = [super init]) {
|
|
37
|
-
self.
|
|
20
|
+
self.audioAPIModule = audioAPIModule;
|
|
38
21
|
self.playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];
|
|
39
22
|
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
|
|
40
23
|
}
|
|
24
|
+
|
|
41
25
|
return self;
|
|
42
26
|
}
|
|
43
27
|
|
|
@@ -176,31 +160,31 @@ static LockScreenManager *_sharedInstance = nil;
|
|
|
176
160
|
{
|
|
177
161
|
MPRemoteCommandCenter *remoteCenter = [MPRemoteCommandCenter sharedCommandCenter];
|
|
178
162
|
|
|
179
|
-
if ([name isEqual:@"
|
|
163
|
+
if ([name isEqual:@"remotePlay"]) {
|
|
180
164
|
[self enableCommand:remoteCenter.playCommand withSelector:@selector(onPlay:) enabled:enabled];
|
|
181
|
-
} else if ([name isEqual:@"
|
|
165
|
+
} else if ([name isEqual:@"remotePause"]) {
|
|
182
166
|
[self enableCommand:remoteCenter.pauseCommand withSelector:@selector(onPause:) enabled:enabled];
|
|
183
|
-
} else if ([name isEqual:@"
|
|
167
|
+
} else if ([name isEqual:@"remoteStop"]) {
|
|
184
168
|
[self enableCommand:remoteCenter.stopCommand withSelector:@selector(onStop:) enabled:enabled];
|
|
185
|
-
} else if ([name isEqual:@"
|
|
169
|
+
} else if ([name isEqual:@"remoteTogglePlayPause"]) {
|
|
186
170
|
[self enableCommand:remoteCenter.togglePlayPauseCommand withSelector:@selector(onTogglePlayPause:) enabled:enabled];
|
|
187
|
-
} else if ([name isEqual:@"
|
|
171
|
+
} else if ([name isEqual:@"remoteChangePlaybackRate"]) {
|
|
188
172
|
[self enableCommand:remoteCenter.changePlaybackRateCommand
|
|
189
173
|
withSelector:@selector(onChangePlaybackRate:)
|
|
190
174
|
enabled:enabled];
|
|
191
|
-
} else if ([name isEqual:@"
|
|
175
|
+
} else if ([name isEqual:@"remoteNextTrack"]) {
|
|
192
176
|
[self enableCommand:remoteCenter.nextTrackCommand withSelector:@selector(onNextTrack:) enabled:enabled];
|
|
193
|
-
} else if ([name isEqual:@"
|
|
177
|
+
} else if ([name isEqual:@"remotePreviousTrack"]) {
|
|
194
178
|
[self enableCommand:remoteCenter.previousTrackCommand withSelector:@selector(onPreviousTrack:) enabled:enabled];
|
|
195
|
-
} else if ([name isEqual:@"
|
|
179
|
+
} else if ([name isEqual:@"remoteSkipForward"]) {
|
|
196
180
|
[self enableCommand:remoteCenter.skipForwardCommand withSelector:@selector(onSkipForward:) enabled:enabled];
|
|
197
|
-
} else if ([name isEqual:@"
|
|
181
|
+
} else if ([name isEqual:@"remoteSkipBackward"]) {
|
|
198
182
|
[self enableCommand:remoteCenter.skipBackwardCommand withSelector:@selector(onSkipBackward:) enabled:enabled];
|
|
199
|
-
} else if ([name isEqual:@"
|
|
183
|
+
} else if ([name isEqual:@"remoteSeekForward"]) {
|
|
200
184
|
[self enableCommand:remoteCenter.seekForwardCommand withSelector:@selector(onSeekForward:) enabled:enabled];
|
|
201
|
-
} else if ([name isEqual:@"
|
|
185
|
+
} else if ([name isEqual:@"remoteSeekBackward"]) {
|
|
202
186
|
[self enableCommand:remoteCenter.seekBackwardCommand withSelector:@selector(onSeekBackward:) enabled:enabled];
|
|
203
|
-
} else if ([name isEqual:@"
|
|
187
|
+
} else if ([name isEqual:@"remoteChangePlaybackPosition"]) {
|
|
204
188
|
[self enableCommand:remoteCenter.changePlaybackPositionCommand
|
|
205
189
|
withSelector:@selector(onChangePlaybackPosition:)
|
|
206
190
|
enabled:enabled];
|
|
@@ -218,77 +202,81 @@ static LockScreenManager *_sharedInstance = nil;
|
|
|
218
202
|
|
|
219
203
|
- (MPRemoteCommandHandlerStatus)onPlay:(MPRemoteCommandEvent *)event
|
|
220
204
|
{
|
|
221
|
-
[self.
|
|
205
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remotePlay" eventBody:nil];
|
|
222
206
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
223
207
|
}
|
|
224
208
|
|
|
225
209
|
- (MPRemoteCommandHandlerStatus)onPause:(MPRemoteCommandEvent *)event
|
|
226
210
|
{
|
|
227
|
-
[self.
|
|
211
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remotePause" eventBody:nil];
|
|
228
212
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
229
213
|
}
|
|
230
214
|
|
|
231
215
|
- (MPRemoteCommandHandlerStatus)onStop:(MPRemoteCommandEvent *)event
|
|
232
216
|
{
|
|
233
|
-
[self.
|
|
217
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteStop" eventBody:nil];
|
|
234
218
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
235
219
|
}
|
|
236
220
|
|
|
237
221
|
- (MPRemoteCommandHandlerStatus)onTogglePlayPause:(MPRemoteCommandEvent *)event
|
|
238
222
|
{
|
|
239
|
-
[self.
|
|
223
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteTogglePlayPause" eventBody:nil];
|
|
240
224
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
241
225
|
}
|
|
242
226
|
|
|
243
227
|
- (MPRemoteCommandHandlerStatus)onChangePlaybackRate:(MPChangePlaybackRateCommandEvent *)event
|
|
244
228
|
{
|
|
245
|
-
|
|
246
|
-
|
|
229
|
+
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.playbackRate]};
|
|
230
|
+
|
|
231
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteChangePlaybackRate" eventBody:body];
|
|
247
232
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
248
233
|
}
|
|
249
234
|
|
|
250
235
|
- (MPRemoteCommandHandlerStatus)onNextTrack:(MPRemoteCommandEvent *)event
|
|
251
236
|
{
|
|
252
|
-
[self.
|
|
237
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteNextTrack" eventBody:nil];
|
|
253
238
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
254
239
|
}
|
|
255
240
|
|
|
256
241
|
- (MPRemoteCommandHandlerStatus)onPreviousTrack:(MPRemoteCommandEvent *)event
|
|
257
242
|
{
|
|
258
|
-
[self.
|
|
243
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remotePreviousTrack" eventBody:nil];
|
|
259
244
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
260
245
|
}
|
|
261
246
|
|
|
262
247
|
- (MPRemoteCommandHandlerStatus)onSeekForward:(MPRemoteCommandEvent *)event
|
|
263
248
|
{
|
|
264
|
-
[self.
|
|
249
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSeekForward" eventBody:nil];
|
|
265
250
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
266
251
|
}
|
|
267
252
|
|
|
268
253
|
- (MPRemoteCommandHandlerStatus)onSeekBackward:(MPRemoteCommandEvent *)event
|
|
269
254
|
{
|
|
270
|
-
[self.
|
|
255
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSeekBackward" eventBody:nil];
|
|
271
256
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
272
257
|
}
|
|
273
258
|
|
|
274
259
|
- (MPRemoteCommandHandlerStatus)onSkipForward:(MPSkipIntervalCommandEvent *)event
|
|
275
260
|
{
|
|
276
|
-
|
|
277
|
-
|
|
261
|
+
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.interval]};
|
|
262
|
+
|
|
263
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSkipForward" eventBody:body];
|
|
278
264
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
279
265
|
}
|
|
280
266
|
|
|
281
267
|
- (MPRemoteCommandHandlerStatus)onSkipBackward:(MPSkipIntervalCommandEvent *)event
|
|
282
268
|
{
|
|
283
|
-
|
|
284
|
-
|
|
269
|
+
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.interval]};
|
|
270
|
+
|
|
271
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSkipBackward" eventBody:body];
|
|
285
272
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
286
273
|
}
|
|
287
274
|
|
|
288
275
|
- (MPRemoteCommandHandlerStatus)onChangePlaybackPosition:(MPChangePlaybackPositionCommandEvent *)event
|
|
289
276
|
{
|
|
290
|
-
|
|
291
|
-
|
|
277
|
+
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.positionTime]};
|
|
278
|
+
|
|
279
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"remoteChangePlaybackPosition" eventBody:body];
|
|
292
280
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
293
281
|
}
|
|
294
282
|
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
#import <AVFoundation/AVFoundation.h>
|
|
4
4
|
#import <Foundation/Foundation.h>
|
|
5
5
|
|
|
6
|
-
@class
|
|
6
|
+
@class AudioAPIModule;
|
|
7
7
|
|
|
8
8
|
@interface NotificationManager : NSObject
|
|
9
9
|
|
|
10
|
-
@property (nonatomic, weak)
|
|
10
|
+
@property (nonatomic, weak) AudioAPIModule *audioAPIModule;
|
|
11
11
|
@property (nonatomic, weak) NSNotificationCenter *notificationCenter;
|
|
12
12
|
|
|
13
13
|
@property (nonatomic, assign) bool isInterrupted;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
@property (nonatomic, assign) bool audioInterruptionsObserved;
|
|
16
16
|
@property (nonatomic, assign) bool volumeChangesObserved;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
- (instancetype)initWithAudioAPIModule:(AudioAPIModule *)audioAPIModule;
|
|
19
19
|
- (void)cleanup;
|
|
20
20
|
|
|
21
21
|
- (void)observeAudioInterruptions:(BOOL)enabled;
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
#import <audioapi/ios/
|
|
1
|
+
#import <audioapi/ios/AudioAPIModule.h>
|
|
2
2
|
#import <audioapi/ios/system/AudioEngine.h>
|
|
3
3
|
#import <audioapi/ios/system/AudioSessionManager.h>
|
|
4
4
|
#import <audioapi/ios/system/NotificationManager.h>
|
|
5
5
|
|
|
6
6
|
@implementation NotificationManager
|
|
7
7
|
|
|
8
|
-
static NotificationManager *_sharedInstance = nil;
|
|
9
8
|
static NSString *VolumeObservationContext = @"VolumeObservationContext";
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
static dispatch_once_t onceToken;
|
|
14
|
-
dispatch_once(&onceToken, ^{
|
|
15
|
-
_sharedInstance = [[self alloc] initPrivateWithAudioManagerModule:audioManagerModule];
|
|
16
|
-
});
|
|
17
|
-
return _sharedInstance;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
- (instancetype)init
|
|
21
|
-
{
|
|
22
|
-
@throw [NSException exceptionWithName:@"Singleton" reason:@"Use +[NotificationManager sharedInstance]" userInfo:nil];
|
|
23
|
-
return nil;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
- (instancetype)initPrivateWithAudioManagerModule:(AudioManagerModule *)audioManagerModule
|
|
10
|
+
- (instancetype)initWithAudioAPIModule:(AudioAPIModule *)audioAPIModule
|
|
27
11
|
{
|
|
28
12
|
if (self = [super init]) {
|
|
29
|
-
self.
|
|
13
|
+
self.audioAPIModule = audioAPIModule;
|
|
30
14
|
self.notificationCenter = [NSNotificationCenter defaultCenter];
|
|
31
15
|
self.audioInterruptionsObserved = false;
|
|
32
16
|
|
|
@@ -84,8 +68,9 @@ static NSString *VolumeObservationContext = @"VolumeObservationContext";
|
|
|
84
68
|
context:(void *)context
|
|
85
69
|
{
|
|
86
70
|
if ([keyPath isEqualToString:@"outputVolume"] && context == &VolumeObservationContext) {
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
NSDictionary *body = @{@"value" : [NSNumber numberWithFloat:[change[@"new"] floatValue]]};
|
|
72
|
+
|
|
73
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"volumeChange" eventBody:body];
|
|
89
74
|
}
|
|
90
75
|
}
|
|
91
76
|
|
|
@@ -115,17 +100,22 @@ static NSString *VolumeObservationContext = @"VolumeObservationContext";
|
|
|
115
100
|
NSInteger interruptionOption = [notification.userInfo[AVAudioSessionInterruptionOptionKey] integerValue];
|
|
116
101
|
|
|
117
102
|
if (interruptionType == AVAudioSessionInterruptionTypeBegan) {
|
|
118
|
-
|
|
119
|
-
|
|
103
|
+
NSDictionary *body = @{@"type" : @"began", @"shouldResume" : @false};
|
|
104
|
+
|
|
105
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"interruption" eventBody:body];
|
|
120
106
|
return;
|
|
121
107
|
}
|
|
122
108
|
|
|
123
109
|
if (interruptionOption == AVAudioSessionInterruptionOptionShouldResume) {
|
|
124
|
-
|
|
110
|
+
NSDictionary *body = @{@"type" : @"ended", @"shouldResume" : @true};
|
|
111
|
+
|
|
112
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"interruption" eventBody:body];
|
|
125
113
|
return;
|
|
126
114
|
}
|
|
127
115
|
|
|
128
|
-
|
|
116
|
+
NSDictionary *body = @{@"type" : @"ended", @"shouldResume" : @false};
|
|
117
|
+
|
|
118
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"interruption" eventBody:body];
|
|
129
119
|
}
|
|
130
120
|
|
|
131
121
|
- (void)handleRouteChange:(NSNotification *)notification
|
|
@@ -163,14 +153,16 @@ static NSString *VolumeObservationContext = @"VolumeObservationContext";
|
|
|
163
153
|
break;
|
|
164
154
|
}
|
|
165
155
|
|
|
166
|
-
|
|
156
|
+
NSDictionary *body = @{@"reason" : reasonStr};
|
|
157
|
+
|
|
158
|
+
[self.audioAPIModule invokeHandlerWithEventName:@"routeChange" eventBody:body];
|
|
167
159
|
}
|
|
168
160
|
|
|
169
161
|
- (void)handleMediaServicesReset:(NSNotification *)notification
|
|
170
162
|
{
|
|
171
163
|
NSLog(@"[NotificationManager] Media services have been reset, tearing down and rebuilding everything.");
|
|
172
|
-
AudioEngine *audioEngine =
|
|
173
|
-
AudioSessionManager *audioSessionManager =
|
|
164
|
+
AudioEngine *audioEngine = self.audioAPIModule.audioEngine;
|
|
165
|
+
AudioSessionManager *audioSessionManager = self.audioAPIModule.audioSessionManager;
|
|
174
166
|
|
|
175
167
|
[self cleanup];
|
|
176
168
|
[audioSessionManager configureAudioSession];
|
|
@@ -180,7 +172,7 @@ static NSString *VolumeObservationContext = @"VolumeObservationContext";
|
|
|
180
172
|
|
|
181
173
|
- (void)handleEngineConfigurationChange:(NSNotification *)notification
|
|
182
174
|
{
|
|
183
|
-
AudioEngine *audioEngine =
|
|
175
|
+
AudioEngine *audioEngine = self.audioAPIModule.audioEngine;
|
|
184
176
|
|
|
185
177
|
if (![audioEngine isRunning]) {
|
|
186
178
|
NSLog(
|
package/lib/commonjs/api.js
CHANGED
|
@@ -177,7 +177,7 @@ Object.defineProperty(exports, "useSystemVolume", {
|
|
|
177
177
|
return _useSytemVolume.default;
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
|
-
var
|
|
180
|
+
var _specs = require("./specs");
|
|
181
181
|
var _AudioBuffer = _interopRequireDefault(require("./core/AudioBuffer"));
|
|
182
182
|
var _AudioBufferSourceNode = _interopRequireDefault(require("./core/AudioBufferSourceNode"));
|
|
183
183
|
var _AudioContext = _interopRequireDefault(require("./core/AudioContext"));
|
|
@@ -202,10 +202,10 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
202
202
|
|
|
203
203
|
/* eslint-disable no-var */
|
|
204
204
|
|
|
205
|
-
if (global.createAudioContext == null || global.createOfflineAudioContext == null || global.createAudioRecorder == null) {
|
|
206
|
-
if (!
|
|
205
|
+
if (global.createAudioContext == null || global.createOfflineAudioContext == null || global.createAudioRecorder == null || global.AudioEventEmitter == null) {
|
|
206
|
+
if (!_specs.NativeAudioAPIModule) {
|
|
207
207
|
throw new Error(`Failed to install react-native-audio-api: The native module could not be found.`);
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
_specs.NativeAudioAPIModule.install();
|
|
210
210
|
}
|
|
211
211
|
//# sourceMappingURL=api.js.map
|