| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // CameraViewFactory1.swift
- // Pods
- //
- // Created by jiajunzhou on 2020/4/5.
- //
- import Foundation
- import Flutter
- import UIKit
- import AliyunVideoSDKPro
- public class CameraViewFactory1 :NSObject,FlutterPlatformViewFactory{
- var messenger: FlutterBinaryMessenger!
- public func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
- return CameraView1(withFrame: frame, viewIdentifier: viewId, arguments: args, binaryMessenger: messenger)
- }
- @objc public init(messenger: (NSObject & FlutterBinaryMessenger)?) {
- super.init()
- self.messenger = messenger
- }
-
- }
- public class CameraView1: NSObject, FlutterPlatformView,AliyunIRecorderDelegate{
- public func recorderDeviceAuthorization(_ status: AliyunIRecorderDeviceAuthor) {
- if status == AliyunIRecorderDeviceAuthor.enabled {
- print("sdk enabled")
- } else {
- print("sdk disabled")
- }
- }
- public func recorderDidStopRecording(){
- print("recorderDidStopRecording.....");
- }
-
- // 调用stopRecording停止录制后,SDK内部会执行保存视频相关操作,收到AliyunIRecorderDelegate的- (void)recorderDidStopRecording回调后才能继续执行其他操作。
- // startRecording和stopRecording需要成对出现,可以调用一次或多次,对应SDK内部会生成一段或多段临时视频文件。
-
-
-
- public func view() -> UIView {
- return self.cameraView
- }
- fileprivate var viewId: Int64!
- fileprivate var cameraView: UIView!
- fileprivate var channel: FlutterMethodChannel!
- fileprivate var recordPath: String?
- fileprivate var taskPath: String?
- fileprivate var recorder: AliyunIRecorder!
- fileprivate var composeResult: FlutterResult?
- //初始设置参数
- var videoWidth : Int!
- var videoHeight : Int!
- var fps : Int!
- var videoCodecs : Int!
- var crf : Int!
- var encoderFps : Int!
- var quality : Int!
- var videoBitrate : Int!
- var gop : Int!
- var first :Bool = true;
- public init(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?, binaryMessenger: FlutterBinaryMessenger) {
- super.init()
-
- self.viewId = viewId
-
- self.cameraView = UIView()
- self.cameraView.frame = UIScreen.main.bounds
- self.channel = FlutterMethodChannel(name: "flutter_ali_camera", binaryMessenger: binaryMessenger)
- self.channel.setMethodCallHandler({
- [weak self]
- (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
- if let this = self {
- this.onMethodCall(call: call, result: result)
- }
- })
- }
- func onMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) {
- if(call.method=="initializeSdk"){
- result(true);
- }
- else if(call.method=="create"){
- let args = call.arguments as? [String: Any]
- var dics = args!["recordOption"] as? Dictionary<String, Int>
- self.videoHeight = dics!["videoHeight"]
- self.videoWidth = dics!["videoWidth"]
- self.fps = dics!["fps"]
- self.videoCodecs = dics!["videoCodecs"]
- self.crf = dics!["crf"]
- self.encoderFps = dics!["encoderFps"]
- self.quality = dics!["quality"]
- self.videoBitrate = dics!["videoBitrate"]
- self.gop = dics!["gop"]
-
- // recorder = AliyunIRecorder.init(delegate: self, videoSize: CGSize(width: 720 , height: 1080))
- // recorder?.preview = self.cameraView
- // recorder?.taskPath = self.taskPath
- // recorder?.clipManager?.maxDuration = 0
-
- result(true);
- }else if(call.method=="startPreview"){
- if(first){
- first=false;
- recorder = AliyunIRecorder.init(delegate: self, videoSize: CGSize(width: videoWidth , height: videoHeight))
- recorder?.preview = self.cameraView
- recorder?.taskPath = self.taskPath
- recorder?.clipManager?.maxDuration = 0
- recorder?.clipManager?.deleteAllPart()
- recorder.beautifyStatus = true
- }
-
- recorder?.startPreview(withPositon: AliyunIRecorderCameraPosition.front)
-
- }
- else if(call.method=="stopPreview"){
- onStop();
- result(true);
- }
- else if(call.method=="setBeauty"){
-
- let args = call.arguments as? Dictionary<String, Int>
- let level = args!["level"] as! Int
- recorder.beautifyValue = Int32(level)
- }
- else if(call.method=="switchCamera"){
- recorder.switchCameraPosition();
- result(true);
- }
- else if(call.method=="setFilter"){
- //未验证
- let args = call.arguments as? Dictionary<String, String>
- let path = args?["path"]
- if path == nil || path?.count == 0 {
- // delete filter
- recorder?.deleteFilter()
- return
- }
- recorder?.apply(AliyunEffectFilter.init(file: path))
- }
- else if(call.method=="startRecord"){
- let args = call.arguments as? Dictionary<String, Int>
- let maxDuration = args!["max"] as! Int
- var fileName = args!["recordPath"] as! String
- print("fileNamefileNamefileName=="+fileName)
- recorder?.outputPath = fileName
-
- recorder?.clipManager?.maxDuration = CGFloat(Float(maxDuration) / 1000.0)
- recorder?.startRecording()
- }
- else if(call.method=="startCompose"){
-
- }
- else if(call.method=="recordUpdate"){
-
- }
- else if(call.method=="onDestroy"){
-
- }
- else {
- result(FlutterMethodNotImplemented)
- }
- }
-
-
- private func onStop() {
- recorder?.stopRecording()
- recorder?.stopPreview()
- }
-
- }
|