@@ -130,7 +130,7 @@ void main() {
130130 );
131131 });
132132
133- test ('stopImageStream() throws $CameraException when recording videos ' ,
133+ test ('stopImageStream() throws $CameraException when not streaming images ' ,
134134 () async {
135135 final CameraController cameraController = CameraController (
136136 const CameraDescription (
@@ -140,50 +140,61 @@ void main() {
140140 ResolutionPreset .max);
141141 await cameraController.initialize ();
142142
143- await cameraController.startImageStream ((CameraImage image) => null );
144- cameraController.value =
145- cameraController.value.copyWith (isRecordingVideo: true );
146143 expect (
147144 cameraController.stopImageStream,
148145 throwsA (isA <CameraException >().having (
149146 (CameraException error) => error.description,
150- 'A video recording is already started. ' ,
151- 'stopImageStream was called while a video is being recorded .' ,
147+ 'No camera is streaming images ' ,
148+ 'stopImageStream was called when no camera is streaming images .' ,
152149 )));
153150 });
154151
155- test ('stopImageStream() throws $CameraException when not streaming images' ,
156- () async {
152+ test ('stopImageStream() intended behaviour' , () async {
157153 final CameraController cameraController = CameraController (
158154 const CameraDescription (
159155 name: 'cam' ,
160156 lensDirection: CameraLensDirection .back,
161157 sensorOrientation: 90 ),
162158 ResolutionPreset .max);
163159 await cameraController.initialize ();
160+ await cameraController.startImageStream ((CameraImage image) => null );
161+ await cameraController.stopImageStream ();
162+
163+ expect (mockPlatform.streamCallLog,
164+ < String > ['onStreamedFrameAvailable' , 'listen' , 'cancel' ]);
165+ });
166+
167+ test ('startVideoRecording() can stream images' , () async {
168+ final CameraController cameraController = CameraController (
169+ const CameraDescription (
170+ name: 'cam' ,
171+ lensDirection: CameraLensDirection .back,
172+ sensorOrientation: 90 ),
173+ ResolutionPreset .max);
174+
175+ await cameraController.initialize ();
176+
177+ cameraController.startVideoRecording (
178+ onAvailable: (CameraImage image) => null );
164179
165180 expect (
166- cameraController.stopImageStream,
167- throwsA (isA <CameraException >().having (
168- (CameraException error) => error.description,
169- 'No camera is streaming images' ,
170- 'stopImageStream was called when no camera is streaming images.' ,
171- )));
181+ mockPlatform.streamCallLog.contains ('startVideoCapturing with stream' ),
182+ isTrue);
172183 });
173184
174- test ('stopImageStream () intended behaviour ' , () async {
185+ test ('startVideoRecording () by default does not stream ' , () async {
175186 final CameraController cameraController = CameraController (
176187 const CameraDescription (
177188 name: 'cam' ,
178189 lensDirection: CameraLensDirection .back,
179190 sensorOrientation: 90 ),
180191 ResolutionPreset .max);
192+
181193 await cameraController.initialize ();
182- await cameraController.startImageStream ((CameraImage image) => null );
183- await cameraController.stopImageStream ();
184194
185- expect (mockPlatform.streamCallLog,
186- < String > ['onStreamedFrameAvailable' , 'listen' , 'cancel' ]);
195+ cameraController.startVideoRecording ();
196+
197+ expect (mockPlatform.streamCallLog.contains ('startVideoCapturing' ), isTrue);
187198 });
188199}
189200
@@ -203,6 +214,24 @@ class MockStreamingCameraPlatform extends MockCameraPlatform {
203214 return _streamController! .stream;
204215 }
205216
217+ @override
218+ Future <XFile > startVideoRecording (int cameraId,
219+ {Duration ? maxVideoDuration}) {
220+ streamCallLog.add ('startVideoRecording' );
221+ return super
222+ .startVideoRecording (cameraId, maxVideoDuration: maxVideoDuration);
223+ }
224+
225+ @override
226+ Future <void > startVideoCapturing (VideoCaptureOptions options) {
227+ if (options.streamCallback == null ) {
228+ streamCallLog.add ('startVideoCapturing' );
229+ } else {
230+ streamCallLog.add ('startVideoCapturing with stream' );
231+ }
232+ return super .startVideoCapturing (options);
233+ }
234+
206235 void _onFrameStreamListen () {
207236 streamCallLog.add ('listen' );
208237 }
0 commit comments