fix(iOS): replace FileHandle(forWritingTo:) with Data concatenation for TS merge

FileHandle(forWritingTo:) throws when file doesn't exist — it opens, not creates.
Changed to Data.append + Data.write which creates the file automatically.
This commit is contained in:
yumoqing 2026-07-17 21:31:51 +08:00
parent f73bc4532e
commit 1f8ecb9bcb

View File

@ -216,15 +216,14 @@ final class HLSRecorder: ObservableObject {
NSLog("[MiniPlayer] Recording loop exited: %d segments downloaded", downloadedSegments.count)
// 4. TS
// 4. TS Data FileHandle(forWritingTo:)
let mergedTS = tempDir.appendingPathComponent("merged.ts")
let output = try FileHandle(forWritingTo: mergedTS)
var mergedData = Data()
for segFile in downloadedSegments {
let segData = try Data(contentsOf: segFile)
output.write(segData)
mergedData.append(try Data(contentsOf: segFile))
}
output.closeFile()
NSLog("[MiniPlayer] Merged %d segments → %@", downloadedSegments.count, mergedTS.path)
try mergedData.write(to: mergedTS)
NSLog("[MiniPlayer] Merged %d segments → %@ (%d bytes)", downloadedSegments.count, mergedTS.path, mergedData.count)
// 5. TS MP4
let outputURL = try await remuxToMP4(tsURL: mergedTS)