Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.23+1

* Fixes error handling in `startWriting`.

## 0.9.23

* Changes the default storage path for camera pictures and videos on iOS from the application's Documents directory to the system's temporaryDirectory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,32 @@ final class CameraSampleBufferTests: XCTestCase {
appendAudioSample(12, 1)
XCTAssertEqual(appendedTime, CMTimeMake(value: 2, timescale: 1))
}

func testStartVideoRecordingReportsErrorWhenStartWritingFails() {
let (camera, writerMock, _, _) = createCamera()

// Configure the mock to return false for startWriting
writerMock.startWritingStub = {
return false
}

// Configure a mock error
let mockError = NSError(
domain: "test", code: 123, userInfo: [NSLocalizedDescriptionKey: "Mock write error"])
writerMock.error = mockError

let expectation = self.expectation(description: "Completion handler called with error")

camera.startVideoRecording(
completion: { error in
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "IOError")
XCTAssertEqual(error?.message, "AVAssetWriter failed to start writing")
XCTAssertEqual(error?.details as? String, "Mock write error")
XCTAssertFalse(camera.isRecording)
expectation.fulfill()
}, messengerForStreaming: nil)

waitForExpectations(timeout: 1.0, handler: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class DefaultCamera: NSObject, Camera {
private var latestPixelBuffer: CVPixelBuffer?

private var videoRecordingPath: String?
private var isRecording = false
private(set) var isRecording = false
private var isRecordingPaused = false
private var isFirstVideoSample = false
private var isAudioSetup = false
Expand Down Expand Up @@ -543,7 +543,14 @@ final class DefaultCamera: NSObject, Camera {
// didOutputSampleBuffer had chance to call startWriting and lag at start of video
// https://github.com/flutter/flutter/issues/132016
// https://github.com/flutter/flutter/issues/151319
let _ = videoWriter?.startWriting()
guard let videoWriter = videoWriter, videoWriter.startWriting() else {
completion(
FlutterError(
code: "IOError",
message: "AVAssetWriter failed to start writing",
details: videoWriter?.error?.localizedDescription))
return
}
isFirstVideoSample = true
isRecording = true
isRecordingPaused = false
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.23
version: 0.9.23+1

environment:
sdk: ^3.9.0
Expand Down