| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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, String iosTaskPath}) async {
- return _methodChannel.invokeMethod("create",
- {"recordOption": recordOption.toMap(), "iosTaskPath": iosTaskPath});
- }
- 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();
- }
- return _methodChannel.invokeMethod("onDestroy");
- }
- Future _onMethodCallHandler(MethodCall call) {
- switch (call.method) {
- case "recordUpdate":
- _recordController.add(call.arguments);
- break;
- }
- return null;
- }
- }
|