瀏覽代碼

try catch error at dispose

Caijinglong 6 年之前
父節點
當前提交
c016290922
共有 1 個文件被更改,包括 19 次插入5 次删除
  1. 19 5
      android/src/main/java/top/kikt/ijkplayer/Ijk.kt

+ 19 - 5
android/src/main/java/top/kikt/ijkplayer/Ijk.kt

@@ -267,11 +267,25 @@ class Ijk(private val registry: PluginRegistry.Registrar, val options: Map<Strin
     }
 
     fun dispose() {
-        notifyChannel.dispose()
-        methodChannel.setMethodCallHandler(null)
-        textureMediaPlayer.stop()
-        textureMediaPlayer.release()
-        textureEntry.release()
+        tryCatchError {
+            notifyChannel.dispose()
+            methodChannel.setMethodCallHandler(null)
+            textureMediaPlayer.stop()
+        }
+        tryCatchError {
+            textureMediaPlayer.release()
+        }
+        tryCatchError {
+            textureEntry.release()
+        }
+    }
+
+    private fun tryCatchError(runnable: () -> Unit) {
+        try {
+            runnable()
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
     }
 
     private fun play() {