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
Reverted platform_interface changes
  • Loading branch information
danielroek committed Feb 3, 2021
commit 3b8d6edd9d50c59b7edf2ed6b9805b1c3ab07624
Original file line number Diff line number Diff line change
Expand Up @@ -235,40 +235,3 @@ class CameraErrorEvent extends CameraEvent {
@override
int get hashCode => super.hashCode ^ description.hashCode;
}

class VideoRecordedEvent extends CameraEvent {
final XFile file;
final Duration maxVideoDuration;

VideoRecordedEvent(int cameraId, this.file, this.maxVideoDuration)
: super(cameraId);

/// Converts the supplied [Map] to an instance of the [VideoRecordedEvent]
/// class.
VideoRecordedEvent.fromJson(Map<String, dynamic> json)
: file = XFile(json['path']),
maxVideoDuration = json['maxVideoDuration'] != null
? Duration(milliseconds: json['maxVideoDuration'] as int)
: null,
super(json['cameraId']);

/// Converts the [VideoRecordedEvent] instance into a [Map] instance that can be
/// serialized to JSON.
Map<String, dynamic> toJson() => {
'cameraId': cameraId,
'path': file.path,
'maxVideoDuration': maxVideoDuration?.inMilliseconds
};

@override
bool operator ==(Object other) =>
identical(this, other) ||
super == other &&
other is VideoRecordedEvent &&
runtimeType == other.runtimeType &&
maxVideoDuration == other.maxVideoDuration;

@override
int get hashCode =>
super.hashCode ^ file.hashCode ^ maxVideoDuration.hashCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:cross_file/cross_file.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
import 'package:pedantic/pedantic.dart';
import 'package:stream_transform/stream_transform.dart';

const MethodChannel _channel = MethodChannel('plugins.flutter.io/camera');
Expand Down Expand Up @@ -157,11 +156,6 @@ class MethodChannelCamera extends CameraPlatform {
return _cameraEvents(cameraId).whereType<CameraErrorEvent>();
}

@override
Stream<VideoRecordedEvent> onVideoRecordedEvent(int cameraId) {
return _cameraEvents(cameraId).whereType<VideoRecordedEvent>();
}

@override
Stream<DeviceOrientationChangedEvent> onDeviceOrientationChanged() {
return deviceEventStreamController.stream
Expand Down Expand Up @@ -215,15 +209,11 @@ class MethodChannelCamera extends CameraPlatform {

@override
Future<XFile> stopVideoRecording(int cameraId) async {
Completer<XFile> completer = Completer();
unawaited(onVideoRecordedEvent(cameraId)
.first
.then((event) => completer.complete(event.file)));
unawaited(_channel.invokeMethod<void>(
String path = await _channel.invokeMethod<String>(
'stopVideoRecording',
<String, dynamic>{'cameraId': cameraId},
));
return completer.future;
);
return XFile(path);
}

@override
Expand Down Expand Up @@ -431,15 +421,6 @@ class MethodChannelCamera extends CameraPlatform {
call.arguments['focusPointSupported'],
));
break;
case 'video_recorded':
cameraEventStreamController.add(VideoRecordedEvent(
cameraId,
XFile(call.arguments['path']),
call.arguments['maxVideoDuration'] != null
? Duration(milliseconds: call.arguments['maxVideoDuration'])
: null,
));
break;
case 'resolution_changed':
cameraEventStreamController.add(CameraResolutionChangedEvent(
cameraId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('onCameraError() is not implemented.');
}

/// The camera finished recording a video
Stream<VideoRecordedEvent> onVideoRecordedEvent(int cameraId) {
throw UnimplementedError('onCameraTimeLimitReached() is not implemented.');
}

/// The device orientation changed.
///
/// Implementations for this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,29 +512,21 @@ void main() {

test('Should stop a video recording and return the file', () async {
// Arrange
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),
MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: {'stopVideoRecording': '/test/path.mp4'},
);

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

// Assert
expect(nextEvent.file.path, event.file.path);
expect(nextEvent.maxVideoDuration, event.maxVideoDuration);
expect(nextEvent.cameraId, event.cameraId);

// Clean up
await streamQueue.cancel();
expect(channel.log, <Matcher>[
isMethodCall('stopVideoRecording', arguments: {
'cameraId': cameraId,
}),
]);
expect(file.path, '/test/path.mp4');
});

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