[vlc-devel] [vlc-android] [PATCH 2/2] Don't create a new libvlc instance in PhoneStateReceiver if one isn't active

Martin Storsjö martin at martin.st
Wed Oct 12 11:57:42 CEST 2011


This avoids creating new libvlc instances when phone calls are
received, if no libvlc instance exists.
---
 .../src/org/videolan/vlc/android/LibVLC.java       |    5 +++++
 .../videolan/vlc/android/PhoneStateReceiver.java   |   10 +++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/android/LibVLC.java b/vlc-android/src/org/videolan/vlc/android/LibVLC.java
index fb45a88..86ef627 100644
--- a/vlc-android/src/org/videolan/vlc/android/LibVLC.java
+++ b/vlc-android/src/org/videolan/vlc/android/LibVLC.java
@@ -78,6 +78,11 @@ public class LibVLC {
     	return sInstance;
     }
 
+    public static LibVLC getExistingInstance()
+    {
+        return sInstance;
+    }
+
     public void reinit() throws LibVlcException
     {
         destroy();
diff --git a/vlc-android/src/org/videolan/vlc/android/PhoneStateReceiver.java b/vlc-android/src/org/videolan/vlc/android/PhoneStateReceiver.java
index b3dd347..f3e17ca 100644
--- a/vlc-android/src/org/videolan/vlc/android/PhoneStateReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/android/PhoneStateReceiver.java
@@ -12,13 +12,9 @@ public class PhoneStateReceiver extends BroadcastReceiver {
 		@Override
 		public void onCallStateChanged(int state, String incomingNumber) {
 			if (state == TelephonyManager.CALL_STATE_RINGING) {
-				try {
-					LibVLC libVLC = LibVLC.getInstance();
-					if (libVLC.isPlaying())
-						libVLC.pause();
-				} catch (LibVlcException e) {
-					return;
-				}
+				LibVLC libVLC = LibVLC.getExistingInstance();
+				if (libVLC != null && libVLC.isPlaying())
+					libVLC.pause();
 			}
 		}
 	};
-- 
1.7.2.5




More information about the vlc-devel mailing list