Forráskód Böngészése

update: 更新example,修复重复进入不能预览问题

hwh97 5 éve
szülő
commit
287d9e5d6f

+ 11 - 10
android/src/main/kotlin/com/i2edu/flutter_ali_camera/AliCameraView.kt

@@ -38,10 +38,6 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
     private var recorder: AliyunIRecorder? = null
     private val mainHandler: Handler = Handler(Looper.getMainLooper())
 
-    init {
-        setUpView(context)
-    }
-
     private fun setUpView(context: Context) {
         if (frameLayout == null) {
             frameLayout = FrameLayout(context)
@@ -233,19 +229,24 @@ class AliCameraView(private val context: Context, private val channel: MethodCha
     }
 
     fun onDestroy() {
-        recorder?.stopPreview()
-        recorder?.stopRecording()
-        recorder?.destroy()
-        recorder = null
+        if (recorder != null) {
+            recorder?.stopPreview()
+            recorder?.stopRecording()
+            recorder?.destroy()
+            recorder = null
+        }
     }
 
     override fun getView(): View {
+        setUpView(context)
         return frameLayout!!
     }
 
     override fun dispose() {
-        if (frameLayout == null) return
-        frameLayout?.removeView(surfaceView)
+        if (frameLayout != null) {
+            frameLayout?.removeView(surfaceView)
+            frameLayout = null
+        }
         if (surfaceView != null) {
             surfaceView = null
         }