fix: 🐛 Finalize iOS recording before returning path; fix file:// URL parsing#498
Open
lavigarg-simform wants to merge 2 commits into
Open
fix: 🐛 Finalize iOS recording before returning path; fix file:// URL parsing#498lavigarg-simform wants to merge 2 commits into
lavigarg-simform wants to merge 2 commits into
Conversation
6d72878 to
eaaf27c
Compare
macOS preparePlayer still used URL(string:), which mis-parses raw filesystem paths and truncates file:// URLs at `#`/`?` — the same bug already fixed for iOS in this branch. Strip the scheme and percent-decode for URL(fileURLWithPath:) so plain and file:// paths both load. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
eaaf27c to
d5d029a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On iOS,
stopRecording()could return the file path beforeAVAudioRecorderfinished writing the file to disk.stop()finalizes the audio container asynchronously, so reading the file or releasing the recorder immediately produced a truncated/invalid container. The recorded file then failed to load in the player withkAudioFileInvalidFileError("Failed to prepare player").This PR makes the following changes:
1.
AudioRecorder.swift(iOS) — defer the result until the file is finalizedFlutterResult(s) in astopResultsqueue instead of returning immediately.audioRecorderDidFinishRecording(_:successfully:)delegate callback, which fires once the recorder has flushed the file to disk. The result (duration + path) is returned from there via a newfinalizeRecording(_:url:path:)helper.audioRecorder = nil) before callingstop()so a subsequentstartRecordingcan't redirect the URL/path that this stop is finalizing. The finishing recorder's own URL is used when finalizing.stopGenerationcounter) force-finalizes if the delegate never fires, so Dart'sstop()can't hang forever. A stale timer / the loser of delegate-vs-watchdog becomes a no-op.stop()calls now queue and all resolve with the same finalized result — a secondstop()no longer returns an empty map / null path.Int(NaN)crash when the container duration is invalid/unfinished (only convert when finite).stopRecordingis called, finalize synchronously (no callback to wait for).2.
AudioPlayer.swift(iOS + macOS) — harden file URL handlingURL(string:)mis-parses raw filesystem paths that have no scheme, and truncatesfile://URLs at#/?. Nowfile://paths have the scheme stripped (and ahostsegment dropped when present), are percent-decoded, and resolved viaURL(fileURLWithPath:); all other paths go straight toURL(fileURLWithPath:). This prevents anilURL / load failure for plain file paths and for filenames containing#/?.URL(string:)bug introduced with macOS support.Checklist
fix:,feat:,docs:etc).docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #432