| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import 'dart:async';
- import 'dart:convert';
- import 'dart:io';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_ali_camera/camera_option.dart';
- class FlutterAliCameraController {
- static const MethodChannel _channel =
- const MethodChannel('flutter_ali_camera');
- static const String viewType = "com.i2edu.cameraLib";
- final StreamController<Map> _recordController = StreamController.broadcast();
- Stream<Map> get recordUpdate => _recordController.stream;
- static Future<String> get platformVersion async {
- final String version = await _channel.invokeMethod('getPlatformVersion');
- return version;
- }
- static Future<void> initializeSdk() {
- return _channel.invokeMethod("initializeSdk");
- }
- Future<void> create({@required CameraRecordOption recordOption}) async {
- _channel.setMethodCallHandler(_onMethodCallHandler);
- return await _channel.invokeMethod("create", {"recordOption": recordOption.toMap()});
- }
- Widget buildView(VoidCallback onPlatformViewCreated) {
- return Platform.isAndroid
- ? AndroidView(
- viewType: viewType,
- creationParams: {},
- creationParamsCodec: const StandardMessageCodec(),
- onPlatformViewCreated: (id) => onPlatformViewCreated(),
- )
- : UiKitView(
- viewType: viewType,
- creationParams: {},
- creationParamsCodec: const StandardMessageCodec(),
- onPlatformViewCreated: (id) => onPlatformViewCreated(),
- );
- }
- Future<void> startPreview() {
- return _channel.invokeMethod("startPreview");
- }
- Future<void> stopPreview() {
- return _channel.invokeMethod("stopPreview");
- }
- Future<void> switchCamera() {
- return _channel.invokeMethod("switchCamera");
- }
- Future<void> setBeauty(int level) {
- return _channel.invokeMethod("setBeauty", {"level": level});
- }
- Future<void> setFilter(String path) {
- return _channel.invokeMethod("setFilter", {"path": path});
- }
- Future<void> startRecord(int max, String recordPath) {
- return _channel.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 _channel.invokeMethod("startCompose", {
- "outputPath": outputPath,
- "bgmPath": bgmPath,
- "paths": paths,
- "durations": durations,
- "composeOption": option.toMap()
- });
- }
- Future _onMethodCallHandler(MethodCall call) {
- print(call.arguments);
- switch (call.method) {
- case "recordUpdate":
- _recordController.add(call.arguments);
- break;
- }
- return null;
- }
- Future<void> dispose() async {
- return _channel.invokeMethod("onDestroy");
- }
- }
|