Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[camera_web] Recording Video #4210

Merged
merged 32 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0c6fac4
Add Support for Video Recording in Camera Web
ABausG Jul 31, 2021
65b2718
Add Documentation
ABausG Jul 31, 2021
4bd1173
Adding Tests
ABausG Jul 31, 2021
ce42759
Adding Error Handling
ABausG Jul 31, 2021
fdbe131
Formatting
ABausG Jul 31, 2021
4b1ae4c
Add missing call to get RecordedEvent Stream
ABausG Jul 31, 2021
2e6dfec
Rename onVideoRecordedEventStream
ABausG Aug 5, 2021
f252ffc
Unify logic from startVideoRecording and stopVideoRecording
ABausG Aug 5, 2021
d8114ab
throw PlatformExceptions
ABausG Aug 5, 2021
39adc96
Use srcObject
ABausG Aug 5, 2021
4db7748
Add Camera Tests
ABausG Aug 5, 2021
287bd4a
Fix Test and Stopping Video Recording
ABausG Aug 7, 2021
8f0f2fd
Clarify maxVideoDuration Test Issue
ABausG Aug 7, 2021
0e1d690
Merge branch 'upstream/master' into camera_web_recording
bselwe Aug 30, 2021
d38978f
feat: await closing videoRecorderController in Camera
bselwe Aug 30, 2021
ce5c1ca
docs: update video recording comments
bselwe Aug 30, 2021
a517757
feat: throw a CameraWebException if the video recording fails
bselwe Aug 30, 2021
2d1022f
test: add onEnded and onVideoRecordedEvent dispose tests
bselwe Aug 31, 2021
01a6999
test: update Camera video recording tests
bselwe Aug 31, 2021
4df6796
test: add missing CameraPlatform video recording tests
bselwe Aug 31, 2021
1d3906d
Merge branch 'upstream/master' into camera_web_recording
bselwe Aug 31, 2021
3c74e9e
feat: combine ondataavailable video blobs into a single video blob
bselwe Sep 3, 2021
f5863e9
test: update video recording tests for multiple video blobs
bselwe Sep 3, 2021
4552b01
docs: add video recording documentation
bselwe Sep 13, 2021
cd7f80d
feat: add Camera onVideoRecordingError stream
bselwe Sep 13, 2021
01b3210
test: add Camera onVideoRecordingError stream tests
bselwe Sep 13, 2021
c03fea6
feat: emit a CameraErrorEvent on video recording error
bselwe Sep 13, 2021
194db74
test: emit a CameraErrorEvent on video recording error tests
bselwe Sep 13, 2021
24ab126
Merge branch 'upstream/master' into camera_web_recording
bselwe Sep 14, 2021
787ee6b
feat: make prepareForVideoRecording a no-op
bselwe Sep 14, 2021
bc9c72a
Merge branch 'master' into camera_web_recording
ditman Sep 16, 2021
114cc46
Update CHANGELOG and pubspec
ditman Sep 16, 2021
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
166 changes: 166 additions & 0 deletions packages/camera/camera_web/example/integration_test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:ui';
import 'package:camera_web/src/camera.dart';
import 'package:camera_web/src/camera_settings.dart';
import 'package:camera_web/src/types/types.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mocktail/mocktail.dart';
Expand Down Expand Up @@ -297,5 +298,170 @@ void main() {
expect(camera.videoElement.srcObject, isNull);
});
});

group('startVideoRecording', () {
testWidgets('starts a video recording', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

await camera.startVideoRecording();

expect('recording', camera.mediaRecorder!.state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect('recording', camera.mediaRecorder!.state);
expect(camera.mediaRecorder!.state, equals('recording`));

});

testWidgets(
'starts a video recording with a given maxDuration '
'emits a VideoRecordedEvent', (tester) async {
// TODO(abausg) There seems to be an issue with removing the listener and stopping the recorder
/*final maxDuration = Duration(milliseconds: 30);

final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

final eventExpectation = expectLater(camera.onVideoRecordedEvent.map((event) => event.maxVideoDuration), emits(maxDuration));
await camera.startVideoRecording(maxVideoDuration: maxDuration);

await eventExpectation;
expect('inactive', camera.mediaRecorder!.state);*/
});

testWidgets(
'throws PlatformException '
'when maxVideoDuration is 0 milliseconds or less', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();
expect(
() => camera.startVideoRecording(maxVideoDuration: Duration.zero),
throwsA(predicate<PlatformException>(
(ex) => ex.code == CameraErrorCode.notSupported.toString())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
throwsA(predicate<PlatformException>(
(ex) => ex.code == CameraErrorCode.notSupported.toString())));
throwsA(predicate<PlatformException>(
(ex) => ex.code == CameraErrorCode.notSupported.toString(),),),);

});
});

group('pauseVideoRecording', () {
testWidgets('pauses a video recording', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();
await camera.startVideoRecording();

await camera.pauseVideoRecording();

expect('paused', camera.mediaRecorder!.state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect('paused', camera.mediaRecorder!.state);
expect(camera.mediaRecorder!.state, equals('paused'));

});

testWidgets(
'throws a PlatformException '
'if no recording was started', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

expect(
camera.pauseVideoRecording,
throwsA(predicate<PlatformException>((ex) =>
ex.code ==
CameraErrorCode.mediaRecordingNotStarted.toString())));
});
});

group('resumeVideoRecording', () {
testWidgets('resumes a video recording', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

await camera.startVideoRecording();

await camera.pauseVideoRecording();

await camera.resumeVideoRecording();

expect('recording', camera.mediaRecorder!.state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect('recording', camera.mediaRecorder!.state);
expect(camera.mediaRecorder!.state, equals('recording'));

});

testWidgets(
'throws a PlatformException '
'if no recording was started', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

expect(
camera.resumeVideoRecording,
throwsA(predicate<PlatformException>((ex) =>
ex.code ==
CameraErrorCode.mediaRecordingNotStarted.toString())));
});
});

group('stopVideoRecording', () {
testWidgets('stops a video recording and returns a File', (tester) async {
// TODO(abausg) There seems to be an issue with removing the listener and stopping the recorder
/*final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

await camera.startVideoRecording();

final videoFile = await camera.stopVideoRecording();

expect(videoFile, isNotNull);

expect(camera.mediaRecorder, isNull);*/
});

testWidgets(
'throws a PlatformException '
'if no recording was started', (tester) async {
final camera = Camera(
textureId: 1,
cameraSettings: cameraSettings,
);

await camera.initialize();
await camera.play();

expect(
camera.stopVideoRecording,
throwsA(predicate<PlatformException>((ex) =>
ex.code ==
CameraErrorCode.mediaRecordingNotStarted.toString())));
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
throwsA(predicate<PlatformException>((ex) =>
ex.code ==
CameraErrorCode.mediaRecordingNotStarted.toString())));
});
throwsA(predicate<PlatformException>((ex) =>
ex.code ==
CameraErrorCode.mediaRecordingNotStarted.toString(),),),);
});

});
});
}
Loading