| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import 'dart:async';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/services.dart';
- import 'camera_option.dart';
- class CameraViewController {
- MethodChannel _methodChannel;
- final StreamController<Map> _recordController = StreamController.broadcast();
- Stream<Map> get recordUpdate => _recordController.stream;
- CameraViewController({@required int id}) {
- _methodChannel = MethodChannel("com.i2edu.cameraLib/camera_view_$id");
- _methodChannel.setMethodCallHandler(_onMethodCallHandler);
- }
- Future<void> create({@required CameraRecordOption recordOption}) async {
- return _methodChannel.invokeMethod("create", {"recordOption": recordOption.toMap()});
- }
- Future<void> startPreview() {
- return _methodChannel.invokeMethod("startPreview");
- }
- Future<void> stopPreview() {
- return _methodChannel.invokeMethod("stopPreview");
- }
- Future<void> switchCamera() {
- return _methodChannel.invokeMethod("switchCamera");
- }
- Future<void> setBeauty(int level) {
- return _methodChannel.invokeMethod("setBeauty", {"level": level});
- }
- Future<void> setFilter(String path) {
- return _methodChannel.invokeMethod("setFilter", {"path": path});
- }
- Future<void> startRecord(int max, String recordPath) {
- return _methodChannel.invokeMethod("startRecord", {"max": max, "recordPath": recordPath});
- }
- Future<bool> startCompose(String outputPath, String bgmPath,
- List<String> paths, List<int> durations, CameraComposeOption option) {
- if (paths.length != durations.length) {
- print("error: length error");
- return null;
- }
- return _methodChannel.invokeMethod("startCompose", {
- "outputPath": outputPath,
- "bgmPath": bgmPath,
- "paths": paths,
- "durations": durations,
- "composeOption": option.toMap()
- });
- }
- void dispose() async {
- if (!_recordController.isClosed) {
- _recordController.close();
- }
- }
- Future _onMethodCallHandler(MethodCall call) {
- switch (call.method) {
- case "recordUpdate":
- _recordController.add(call.arguments);
- break;
- }
- return null;
- }
- }
|