Skip to content

fix: prevent iOS crash when audio download fails in playFromUrl - #7

Open
bradrice wants to merge 1 commit into
nativescript-community:masterfrom
bradrice:fix-ios-player-reject-crash
Open

bradrice wants to merge 1 commit into
nativescript-community:masterfrom
bradrice:fix-ios-player-reject-crash

Conversation

@bradrice

Copy link
Copy Markdown

Problem

On iOS, TNSPlayer.playFromUrl crashes when the audio download fails. In the NSURLSession.dataTaskWithURLCompletionHandler callback, an error is handled by rejecting the promise — but execution does not stop, so it falls through to:

if (error !== null) {
    if (this.errorCallback) {
        this.errorCallback({ error });
    }
    reject(error);          // ← no return
}
const errorRef = new interop.Reference<NSError>();
const inputSource = SFBInputSource.inputSourceWithData(data);  // data is null → crash

When the request errors, data is null, so SFBInputSource.inputSourceWithData(data) (and the decoder init that follows) runs on invalid data and crashes the app. This shows up in practice as a crash/error when navigating away mid-load or when a track fails to download.

Fix

Return after rejecting so the handler bails out cleanly on error:

-                        reject(error);
+                        return reject(error);

One line, src/audio/player.ios.ts. The other error branches in this handler already return reject(...); this makes the download-error branch consistent with them.

Testing

We've been running this exact change in production (iOS) via patch-package against @nativescript-community/audio@6.4.14, and it resolves the crash. The change is a control-flow guard only — no behavior change on the success path.

In TNSPlayer.playFromUrl, the NSURLSession completion handler rejects the
promise when the download errors but does not return, so execution falls
through to `SFBInputSource.inputSourceWithData(data)` with a null `data`,
crashing on iOS. Return after reject so the handler bails out cleanly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant