@@ -130,7 +130,7 @@ void main() {
130
130
);
131
131
});
132
132
133
- test ('stopImageStream() throws $CameraException when recording videos ' ,
133
+ test ('stopImageStream() throws $CameraException when not streaming images ' ,
134
134
() async {
135
135
final CameraController cameraController = CameraController (
136
136
const CameraDescription (
@@ -140,50 +140,61 @@ void main() {
140
140
ResolutionPreset .max);
141
141
await cameraController.initialize ();
142
142
143
- await cameraController.startImageStream ((CameraImage image) => null );
144
- cameraController.value =
145
- cameraController.value.copyWith (isRecordingVideo: true );
146
143
expect (
147
144
cameraController.stopImageStream,
148
145
throwsA (isA <CameraException >().having (
149
146
(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 .' ,
152
149
)));
153
150
});
154
151
155
- test ('stopImageStream() throws $CameraException when not streaming images' ,
156
- () async {
152
+ test ('stopImageStream() intended behaviour' , () async {
157
153
final CameraController cameraController = CameraController (
158
154
const CameraDescription (
159
155
name: 'cam' ,
160
156
lensDirection: CameraLensDirection .back,
161
157
sensorOrientation: 90 ),
162
158
ResolutionPreset .max);
163
159
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 );
164
179
165
180
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);
172
183
});
173
184
174
- test ('stopImageStream () intended behaviour ' , () async {
185
+ test ('startVideoRecording () by default does not stream ' , () async {
175
186
final CameraController cameraController = CameraController (
176
187
const CameraDescription (
177
188
name: 'cam' ,
178
189
lensDirection: CameraLensDirection .back,
179
190
sensorOrientation: 90 ),
180
191
ResolutionPreset .max);
192
+
181
193
await cameraController.initialize ();
182
- await cameraController.startImageStream ((CameraImage image) => null );
183
- await cameraController.stopImageStream ();
184
194
185
- expect (mockPlatform.streamCallLog,
186
- < String > ['onStreamedFrameAvailable' , 'listen' , 'cancel' ]);
195
+ cameraController.startVideoRecording ();
196
+
197
+ expect (mockPlatform.streamCallLog.contains ('startVideoCapturing' ), isTrue);
187
198
});
188
199
}
189
200
@@ -203,6 +214,24 @@ class MockStreamingCameraPlatform extends MockCameraPlatform {
203
214
return _streamController! .stream;
204
215
}
205
216
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
+
206
235
void _onFrameStreamListen () {
207
236
streamCallLog.add ('listen' );
208
237
}
0 commit comments