Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c7a749a
Added maxVideoDuration to startVideoRecording
danielroek Dec 23, 2020
131918d
updated documentation
danielroek Dec 23, 2020
9b3ae14
updated documentation
danielroek Dec 23, 2020
3ca25df
Fixed long line in docs
danielroek Dec 23, 2020
5e626b9
Formatting
danielroek Dec 23, 2020
02811b7
Started implementation for Android
danielroek Dec 24, 2020
b8b07e2
WIP: Started implementation of stream when time limit is reached
danielroek Dec 24, 2020
aff2938
Merge remote-tracking branch 'origin/master' into limit_video_length
danielroek Jan 8, 2021
532cbb0
Merge remote-tracking branch 'origin/master' into limit_video_length
danielroek Jan 11, 2021
50edc53
Initial working implementation
danielroek Jan 11, 2021
6e31d7c
Android implementation works
danielroek Jan 11, 2021
d3bab02
Improved implementation
danielroek Jan 11, 2021
ae7365c
Updated README order
danielroek Jan 11, 2021
ae1b47c
removed debugPrints
danielroek Jan 11, 2021
4037b5e
Fixed url in README.md
danielroek Jan 11, 2021
36acc32
Formatting
danielroek Jan 11, 2021
5a78233
Merge remote-tracking branch 'origin/master' into limit_video_length
danielroek Jan 13, 2021
09dad16
Implemented Java feedback
danielroek Jan 13, 2021
771f116
Implemented Event and Stream to notify about videoRecording
danielroek Jan 13, 2021
16e43fb
stopVideoRecording now listens to VideoRecordedEvent
danielroek Jan 13, 2021
7cb73ef
Fixed future returning xFile
danielroek Jan 13, 2021
759f163
finished iOS implementation
Feb 3, 2021
0b4270d
Fixed formatting
Feb 3, 2021
12231da
fixed formatting
Feb 3, 2021
3b8d6ed
Reverted platform_interface changes
danielroek Feb 3, 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
Prev Previous commit
Next Next commit
fixed formatting
  • Loading branch information
Daniel Roek committed Feb 3, 2021
commit 12231dab92983e50e71f7a55c3904d4f0448cad4
3 changes: 1 addition & 2 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
}

try {
await controller.startVideoRecording(
maxVideoDuration: Duration(seconds: 5));
await controller.startVideoRecording(maxVideoDuration: null);
} on CameraException catch (e) {
_showCameraException(e);
return;
Expand Down
33 changes: 11 additions & 22 deletions packages/camera/camera/ios/Classes/CameraPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,10 @@ - (void)startVideoRecordingWithResult:(FlutterResult)result
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(maxVideoDuration * NSEC_PER_MSEC)),
dispatch_get_main_queue(), ^{
if (self->_isRecording) {
[self stopVideoRecordingWithResult:nil maxVideoDuration:maxVideoDuration];
[self stopVideoRecording:maxVideoDuration];
}
});
}
// TODO: Set a timer with maxVideoDuration and call stopVideoRecording
// TODO: send videoRecordedEvent to Dart with path and maxVideoDuration
_isRecording = YES;
_isRecordingPaused = NO;
_videoTimeOffset = CMTimeMake(0, 1);
Expand All @@ -789,16 +787,12 @@ - (void)startVideoRecordingWithResult:(FlutterResult)result
}
}

- (void)stopVideoRecordingWithResult:(FlutterResult)result
maxVideoDuration:(int64_t)maxVideoDuration {
- (void)stopVideoRecording:(int64_t)maxVideoDuration {
if (_isRecording) {
_isRecording = NO;
if (_videoWriter.status != AVAssetWriterStatusUnknown) {
[_videoWriter finishWritingWithCompletionHandler:^{
if (self->_videoWriter.status == AVAssetWriterStatusCompleted) {
if (result != nil) {
result(self->_videoRecordingPath);
}
[self->_methodChannel invokeMethod:@"video_recorded"
arguments:@{
@"path" : self->_videoRecordingPath,
Expand All @@ -807,22 +801,13 @@ - (void)stopVideoRecordingWithResult:(FlutterResult)result

self->_videoRecordingPath = nil;
} else {
if (result != nil) {
result([FlutterError errorWithCode:@"IOError"
message:@"AVAssetWriter could not finish writing!"
details:nil]);
}
[self->_methodChannel invokeMethod:errorMethod
arguments:@"AVAssetWriter could not finish writing!"];
}
}];
}
} else {
NSError *error =
[NSError errorWithDomain:NSCocoaErrorDomain
code:NSURLErrorResourceUnavailable
userInfo:@{NSLocalizedDescriptionKey : @"Video is not recording!"}];
result(getFlutterError(error));
[self->_methodChannel invokeMethod:errorMethod arguments:@"Video is not recording!"];
}
}

Expand Down Expand Up @@ -1306,11 +1291,15 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call result:(FlutterResult)re
[_camera setUpCaptureSessionForAudio];
result(nil);
} else if ([@"startVideoRecording" isEqualToString:call.method]) {
[_camera
startVideoRecordingWithResult:result
maxVideoDuration:((NSNumber *)call.arguments[@"maxVideoDuration"]).intValue];
if ([call.arguments[@"maxVideoDuration"] class] != [NSNull class]) {
[_camera startVideoRecordingWithResult:result
maxVideoDuration:((NSNumber *)call.arguments[@"maxVideoDuration"])
.intValue];
} else {
[_camera startVideoRecordingWithResult:result maxVideoDuration:0];
}
} else if ([@"stopVideoRecording" isEqualToString:call.method]) {
[_camera stopVideoRecordingWithResult:result maxVideoDuration:0];
[_camera stopVideoRecording:0];
} else if ([@"pauseVideoRecording" isEqualToString:call.method]) {
[_camera pauseVideoRecordingWithResult:result];
} else if ([@"resumeVideoRecording" isEqualToString:call.method]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class VideoRecordedEvent extends CameraEvent {
super == other &&
other is VideoRecordedEvent &&
runtimeType == other.runtimeType &&
file == other.file &&
maxVideoDuration == other.maxVideoDuration;

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,21 +512,29 @@ void main() {

test('Should stop a video recording and return the file', () async {
// Arrange
MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: {'stopVideoRecording': '/test/path.mp4'},
final Stream<VideoRecordedEvent> eventStream =
camera.onVideoRecordedEvent(cameraId);
final streamQueue = StreamQueue(eventStream);

// Emit test events
final event = VideoRecordedEvent(
cameraId,
XFile('/test/path.mp4'),
Duration(milliseconds: 100),
);

// Act
XFile file = await camera.stopVideoRecording(cameraId);
await camera.handleCameraMethodCall(
MethodCall('video_recorded', event.toJson()), cameraId);
final nextEvent = await streamQueue.next;

// Assert
expect(channel.log, <Matcher>[
isMethodCall('stopVideoRecording', arguments: {
'cameraId': cameraId,
}),
]);
expect(file.path, '/test/path.mp4');
expect(nextEvent.file.path, event.file.path);
expect(nextEvent.maxVideoDuration, event.maxVideoDuration);
expect(nextEvent.cameraId, event.cameraId);

// Clean up
await streamQueue.cancel();
});

test('Should pause a video recording', () async {
Expand Down