import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'camera_option.dart'; class CameraViewController { MethodChannel _methodChannel; final StreamController _recordController = StreamController.broadcast(); Stream get recordUpdate => _recordController.stream; CameraViewController({@required int id}) { _methodChannel = MethodChannel("com.i2edu.cameraLib/camera_view_$id"); _methodChannel.setMethodCallHandler(_onMethodCallHandler); } Future create({@required CameraRecordOption recordOption}) async { return _methodChannel.invokeMethod("create", {"recordOption": recordOption.toMap()}); } Future startPreview() { return _methodChannel.invokeMethod("startPreview"); } Future stopPreview() { return _methodChannel.invokeMethod("stopPreview"); } Future switchCamera() { return _methodChannel.invokeMethod("switchCamera"); } Future setBeauty(int level) { return _methodChannel.invokeMethod("setBeauty", {"level": level}); } Future setFilter(String path) { return _methodChannel.invokeMethod("setFilter", {"path": path}); } Future startRecord(int max, String recordPath) { return _methodChannel.invokeMethod("startRecord", {"max": max, "recordPath": recordPath}); } Future startCompose(String outputPath, String bgmPath, List paths, List 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; } }