From 3cf6c77066ebfeba3e9f78e9f314dfcf8a95c15b Mon Sep 17 00:00:00 2001 From: maobui Date: Wed, 20 Nov 2019 10:47:40 +0700 Subject: [PATCH] - Fix crashed app. --- .../com/example/mediaplayer/MediaPlayerPlugin.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/example/mediaplayer/MediaPlayerPlugin.java b/android/src/main/java/com/example/mediaplayer/MediaPlayerPlugin.java index a74a347..99b314c 100644 --- a/android/src/main/java/com/example/mediaplayer/MediaPlayerPlugin.java +++ b/android/src/main/java/com/example/mediaplayer/MediaPlayerPlugin.java @@ -42,6 +42,7 @@ public class MediaPlayerPlugin implements MethodCallHandler, ViewDestroyListener private MethodCall call = null; private Result result = null; + private boolean bound = false; private ServiceConnection serviceConnection = new ServiceConnection() { @Override @@ -50,14 +51,15 @@ public void onServiceConnected(ComponentName componentName, IBinder iBinder) { audioServiceBinder = (AudioServiceBinder) iBinder; createVideoPlayer(); Log.i("ServiceConnnection", "Service connection audio service binder complete"); + bound = true; } @Override public void onServiceDisconnected(ComponentName componentName) { - Log.i("ServiceConnnection", "Service disconnected"); - + Log.i("ServiceConnnection", "Service disconnected"); + bound = false; } }; @@ -113,7 +115,10 @@ private void unBoundService() { Log.i(TAG, "unbound service called"); if (audioServiceBinder != null){ audioServiceBinder.destroyAllPlayers(); - registrar.context().unbindService(serviceConnection); + if(bound) { + registrar.context().unbindService(serviceConnection); + bound = false; + } Log.i(TAG, "service unbounded"); }