Skip to content

Commit 158da87

Browse files
committed
fix(ios): fixed crash with audio player
1 parent b25a642 commit 158da87

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/audio/player.ios.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class TNSPlayer extends Observable {
145145
const errorRef = new interop.Reference<NSError>();
146146
this._player = AVAudioPlayer.alloc().initWithContentsOfURLError(NSURL.fileURLWithPath(fileName), errorRef);
147147
if (errorRef && errorRef.value) {
148-
throw wrapNativeException(errorRef.value);
148+
reject(wrapNativeException(errorRef.value));
149149
} else if (this._player) {
150150
this.handleStartPlayer(options);
151151

@@ -184,7 +184,7 @@ export class TNSPlayer extends Observable {
184184
const errorRef = new interop.Reference<NSError>();
185185
this._player = AVAudioPlayer.alloc().initWithDataError(data, errorRef);
186186
if (errorRef && errorRef.value) {
187-
throw wrapNativeException(errorRef.value);
187+
reject(wrapNativeException(errorRef.value));
188188
} else if (this._player) {
189189
this.handleStartPlayer(options);
190190

@@ -272,9 +272,7 @@ export class TNSPlayer extends Observable {
272272
audioSession.setActiveError(false);
273273
this._reset();
274274
} catch (ex) {
275-
if (this.errorCallback) {
276-
this.errorCallback({ ex });
277-
}
275+
this.errorCallback?.({ ex });
278276
throw ex;
279277
}
280278
}

src/audio/recorder.ios.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class TNSRecorder extends Observable {
8585
);
8686
//@ts-ignore
8787
if (errorRef && errorRef.value) {
88-
throw wrapNativeException(errorRef.value);
88+
return reject(wrapNativeException(errorRef.value));
8989
}
9090

9191
this._recordingSession.setActiveError(true);
@@ -132,7 +132,7 @@ export class TNSRecorder extends Observable {
132132
this._recorder = AVAudioRecorder.alloc().initWithURLSettingsError(url, recordSetting, errorRef);
133133
}
134134
if (errorRef && errorRef.value) {
135-
throw wrapNativeException(errorRef.value);
135+
reject(wrapNativeException(errorRef.value));
136136
} else {
137137
if (!this._recorder.delegate) {
138138
this._recorder.delegate = TNSRecorderDelegate.initWithOwner(this);

0 commit comments

Comments
 (0)