Skip to content

Commit b294641

Browse files
committed
fix: fixed issue on ios
audio engine needs to be restarted upon changing anything like attaching detaching nodes
1 parent 4d86c14 commit b294641

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioPlayer.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ - (bool)start
4040
assert(audioEngine != nil);
4141
self.sourceNodeId = [audioEngine attachSourceNode:self.sourceNode format:self.format];
4242

43-
return [audioEngine startIfNecessary];
43+
// if the engine is already running we need to restart it to make it use newly attached node
44+
return [audioEngine restartAudioEngine];
4445
}
4546

4647
- (void)stop
@@ -50,6 +51,7 @@ - (void)stop
5051
AudioEngine *audioEngine = [AudioEngine sharedInstance];
5152
assert(audioEngine != nil);
5253
[audioEngine detachSourceNodeWithId:self.sourceNodeId];
54+
[audioEngine restartAudioEngine];
5355
[audioEngine stopIfNecessary];
5456
self.sourceNodeId = nil;
5557
}

packages/react-native-audio-api/ios/audioapi/ios/core/NativeAudioRecorder.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,17 @@ - (void)start
101101
AudioEngine *audioEngine = [AudioEngine sharedInstance];
102102
assert(audioEngine != nil);
103103
[audioEngine attachInputNode:self.sinkNode];
104-
[audioEngine startIfNecessary];
104+
105+
// if the engine is running we need to restart it to make it use newly attached node
106+
[audioEngine restartAudioEngine];
105107
}
106108

107109
- (void)stop
108110
{
109111
AudioEngine *audioEngine = [AudioEngine sharedInstance];
110112
assert(audioEngine != nil);
111113
[audioEngine detachInputNode];
114+
[audioEngine restartAudioEngine];
112115
[audioEngine stopIfNecessary];
113116
}
114117

0 commit comments

Comments
 (0)