|
@@ -25,30 +25,96 @@ import com.aliyun.svideo.sdk.external.struct.encoder.VideoCodecs
|
|
|
import com.aliyun.svideo.sdk.external.struct.recorder.CameraParam
|
|
import com.aliyun.svideo.sdk.external.struct.recorder.CameraParam
|
|
|
import com.aliyun.svideo.sdk.external.struct.recorder.CameraType
|
|
import com.aliyun.svideo.sdk.external.struct.recorder.CameraType
|
|
|
import com.aliyun.svideo.sdk.external.struct.recorder.MediaInfo
|
|
import com.aliyun.svideo.sdk.external.struct.recorder.MediaInfo
|
|
|
|
|
+import io.flutter.plugin.common.BinaryMessenger
|
|
|
|
|
+import io.flutter.plugin.common.MethodCall
|
|
|
import io.flutter.plugin.common.MethodChannel
|
|
import io.flutter.plugin.common.MethodChannel
|
|
|
import io.flutter.plugin.platform.PlatformView
|
|
import io.flutter.plugin.platform.PlatformView
|
|
|
import java.io.File
|
|
import java.io.File
|
|
|
import java.lang.Exception
|
|
import java.lang.Exception
|
|
|
|
|
|
|
|
-class AliCameraView(private val context: Context, private val channel: MethodChannel) : PlatformView {
|
|
|
|
|
|
|
+class AliCameraView(private val context: Context, private val binaryMessenger: BinaryMessenger, id: Int, param: Any?) : PlatformView, MethodChannel.MethodCallHandler {
|
|
|
private val TAG = "AliCameraView"
|
|
private val TAG = "AliCameraView"
|
|
|
var surfaceView: SurfaceView? = null
|
|
var surfaceView: SurfaceView? = null
|
|
|
var frameLayout: FrameLayout? = null
|
|
var frameLayout: FrameLayout? = null
|
|
|
|
|
|
|
|
|
|
+ private var methodChannel: MethodChannel? = null
|
|
|
private var recorder: AliyunIRecorder? = null
|
|
private var recorder: AliyunIRecorder? = null
|
|
|
private val mainHandler: Handler = Handler(Looper.getMainLooper())
|
|
private val mainHandler: Handler = Handler(Looper.getMainLooper())
|
|
|
|
|
|
|
|
- private fun setUpView(context: Context) {
|
|
|
|
|
- if (frameLayout == null) {
|
|
|
|
|
- frameLayout = FrameLayout(context)
|
|
|
|
|
- frameLayout?.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
|
|
- surfaceView = SurfaceView(context)
|
|
|
|
|
- surfaceView?.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
|
|
- frameLayout?.addView(surfaceView)
|
|
|
|
|
|
|
+ init {
|
|
|
|
|
+ frameLayout = FrameLayout(context)
|
|
|
|
|
+ frameLayout?.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
|
|
+ surfaceView = SurfaceView(context)
|
|
|
|
|
+ surfaceView?.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
|
|
|
+ frameLayout?.addView(surfaceView)
|
|
|
|
|
+
|
|
|
|
|
+ methodChannel = MethodChannel(binaryMessenger, "com.i2edu.cameraLib/camera_view_$id")
|
|
|
|
|
+ methodChannel?.setMethodCallHandler(this)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun getView(): View {
|
|
|
|
|
+ return frameLayout!!
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun dispose() {
|
|
|
|
|
+ if (frameLayout != null) {
|
|
|
|
|
+ frameLayout?.removeView(surfaceView)
|
|
|
|
|
+ frameLayout = null
|
|
|
|
|
+ }
|
|
|
|
|
+ if (surfaceView != null) {
|
|
|
|
|
+ surfaceView = null
|
|
|
|
|
+ }
|
|
|
|
|
+ onDestroy()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
+ when (call.method) {
|
|
|
|
|
+ "create" -> {
|
|
|
|
|
+ val recordOption: Map<String, Any> = call.argument<Map<String, Any>>("recordOption")!!
|
|
|
|
|
+ setUpCameraView(recordOption = recordOption)
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ "startPreview" -> {
|
|
|
|
|
+ startPreview()
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ "stopPreview" -> {
|
|
|
|
|
+ stopPreview()
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ "switchCamera" -> {
|
|
|
|
|
+ switchCamera()
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ "setBeauty" -> {
|
|
|
|
|
+ setBeauty(call.argument<Int>("level")!!)
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ "setFilter" -> {
|
|
|
|
|
+ setFilter(call.argument<String>("path")!!)
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ "startRecord" -> {
|
|
|
|
|
+ startRecord(
|
|
|
|
|
+ max = call.argument<Int>("max")!!, recordPath = call.argument<String>("recordPath")!!, result = result)
|
|
|
|
|
+ }
|
|
|
|
|
+ "startCompose" -> {
|
|
|
|
|
+ val outputPath = call.argument<String>("outputPath")!!
|
|
|
|
|
+ val bgmPath = call.argument<String>("bgmPath")
|
|
|
|
|
+ val paths = call.argument<List<String>>("paths")!!
|
|
|
|
|
+ val durations = call.argument<List<Int>>("durations")!!
|
|
|
|
|
+ val outputOption = call.argument<Map<String, Any>>("composeOption")!!
|
|
|
|
|
+ startCompose(outputPath = outputPath, bgmPath = bgmPath, paths = paths, durations = durations, outputOption = outputOption, result = result)
|
|
|
|
|
+ }
|
|
|
|
|
+ "onDestroy" -> {
|
|
|
|
|
+ onDestroy()
|
|
|
|
|
+ result.success(true)
|
|
|
|
|
+ }
|
|
|
|
|
+ else -> result.notImplemented()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun setUpCameraView(context: Context, recordOption: Map<String, Any>) {
|
|
|
|
|
|
|
+ private fun setUpCameraView(recordOption: Map<String, Any>) {
|
|
|
try {
|
|
try {
|
|
|
recorder = AliyunRecorderCreator.getRecorderInstance(context)
|
|
recorder = AliyunRecorderCreator.getRecorderInstance(context)
|
|
|
|
|
|
|
@@ -84,7 +150,7 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
|
|
|
|
|
override fun onComplete(p0: Boolean, p1: Long) {
|
|
override fun onComplete(p0: Boolean, p1: Long) {
|
|
|
mainHandler.post {
|
|
mainHandler.post {
|
|
|
- channel.invokeMethod("recordUpdate",
|
|
|
|
|
|
|
+ methodChannel?.invokeMethod("recordUpdate",
|
|
|
mapOf("progress" to recorder?.clipManager?.maxDuration, "path" to recorder?.clipManager?.videoPathList?.last()))
|
|
mapOf("progress" to recorder?.clipManager?.maxDuration, "path" to recorder?.clipManager?.videoPathList?.last()))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -97,7 +163,7 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
|
|
|
|
|
override fun onProgress(p0: Long) {
|
|
override fun onProgress(p0: Long) {
|
|
|
mainHandler.post {
|
|
mainHandler.post {
|
|
|
- channel.invokeMethod("recordUpdate", mapOf("progress" to p0))
|
|
|
|
|
|
|
+ methodChannel?.invokeMethod("recordUpdate", mapOf("progress" to p0))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -110,24 +176,24 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun startPreview() {
|
|
|
|
|
|
|
+ private fun startPreview() {
|
|
|
recorder?.startPreview()
|
|
recorder?.startPreview()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun stopPreview() {
|
|
|
|
|
|
|
+ private fun stopPreview() {
|
|
|
recorder?.stopPreview()
|
|
recorder?.stopPreview()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun switchCamera() {
|
|
|
|
|
|
|
+ private fun switchCamera() {
|
|
|
recorder?.switchCamera()
|
|
recorder?.switchCamera()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun setBeauty(level: Int) {
|
|
|
|
|
|
|
+ private fun setBeauty(level: Int) {
|
|
|
recorder?.setBeautyStatus(level != 0)
|
|
recorder?.setBeautyStatus(level != 0)
|
|
|
recorder?.beautyLevel = level
|
|
recorder?.beautyLevel = level
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun setFilter(path: String) {
|
|
|
|
|
|
|
+ private fun setFilter(path: String) {
|
|
|
if (path.isEmpty()) {
|
|
if (path.isEmpty()) {
|
|
|
recorder?.applyFilter(EffectFilter(null))
|
|
recorder?.applyFilter(EffectFilter(null))
|
|
|
return
|
|
return
|
|
@@ -135,7 +201,7 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
recorder?.applyFilter(EffectFilter(path))
|
|
recorder?.applyFilter(EffectFilter(path))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun startRecord(max: Int, recordPath: String, result: MethodChannel.Result) {
|
|
|
|
|
|
|
+ private fun startRecord(max: Int, recordPath: String, result: MethodChannel.Result) {
|
|
|
try {
|
|
try {
|
|
|
recorder?.setOutputPath(recordPath)
|
|
recorder?.setOutputPath(recordPath)
|
|
|
// 补充时间段上去
|
|
// 补充时间段上去
|
|
@@ -148,7 +214,7 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun startCompose(outputPath: String, bgmPath: String?, paths: List<String>, durations: List<Int>, outputOption: Map<String, Any>, result: MethodChannel.Result) {
|
|
|
|
|
|
|
+ private fun startCompose(outputPath: String, bgmPath: String?, paths: List<String>, durations: List<Int>, outputOption: Map<String, Any>, result: MethodChannel.Result) {
|
|
|
try {
|
|
try {
|
|
|
// 配置输出参数
|
|
// 配置输出参数
|
|
|
val mImport = AliyunImportCreator.getImportInstance(context)
|
|
val mImport = AliyunImportCreator.getImportInstance(context)
|
|
@@ -228,7 +294,7 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun onDestroy() {
|
|
|
|
|
|
|
+ private fun onDestroy() {
|
|
|
if (recorder != null) {
|
|
if (recorder != null) {
|
|
|
recorder?.stopPreview()
|
|
recorder?.stopPreview()
|
|
|
recorder?.stopRecording()
|
|
recorder?.stopRecording()
|
|
@@ -236,20 +302,4 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
|
|
|
recorder = null
|
|
recorder = null
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- override fun getView(): View {
|
|
|
|
|
- setUpView(context)
|
|
|
|
|
- return frameLayout!!
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- override fun dispose() {
|
|
|
|
|
- if (frameLayout != null) {
|
|
|
|
|
- frameLayout?.removeView(surfaceView)
|
|
|
|
|
- frameLayout = null
|
|
|
|
|
- }
|
|
|
|
|
- if (surfaceView != null) {
|
|
|
|
|
- surfaceView = null
|
|
|
|
|
- }
|
|
|
|
|
- onDestroy()
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|