[Android] [PATCH 4/5] Phone Call : add call ended behaviour

Alexandre Perraud 4leyx4ndre at gmail.com
Thu Sep 11 19:40:21 CEST 2014


    Play if VLC was playing an audio file. Fix #11786.
---
 vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java |  4 ++++
 vlc-android/src/org/videolan/vlc/VLCApplication.java     |  1 +
 vlc-android/src/org/videolan/vlc/audio/AudioService.java | 12 ++++++++++++
 3 files changed, 17 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java b/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java
index b95a0a8..cb43bea 100644
--- a/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java
@@ -35,7 +35,11 @@ public class PhoneStateReceiver extends BroadcastReceiver {
                 state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
             Intent newIntent = new Intent(VLCApplication.INCOMING_CALL_INTENT);
             VLCApplication.getAppContext().sendBroadcast(newIntent);
+        }
 
+        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
+            Intent newIntent = new Intent(VLCApplication.CALL_ENDED_INTENT);
+            VLCApplication.getAppContext().sendBroadcast(newIntent);
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index fc3aca3..e915a46 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -38,6 +38,7 @@ public class VLCApplication extends Application {
 
     public final static String SLEEP_INTENT = "org.videolan.vlc.SleepIntent";
     public final static String INCOMING_CALL_INTENT = "org.videolan.vlc.IncomingCallIntent";
+    public final static String CALL_ENDED_INTENT = "org.videolan.vlc.CallEndedIntent";
 
     @Override
     public void onCreate() {
diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index cb2c313..6da9fc0 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -121,6 +121,8 @@ public class AudioService extends Service {
     private boolean mDetectHeadset = true;
     private PowerManager.WakeLock mWakeLock;
 
+    private static boolean mWasPlayingAudio = false;
+
     // Index management
     /**
      * Stack of previously played indexes, used in shuffle mode
@@ -186,6 +188,7 @@ public class AudioService extends Service {
         filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
         filter.addAction(VLCApplication.SLEEP_INTENT);
         filter.addAction(VLCApplication.INCOMING_CALL_INTENT);
+        filter.addAction(VLCApplication.CALL_ENDED_INTENT);
         registerReceiver(serviceReceiver, filter);
 
         final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
@@ -342,10 +345,19 @@ public class AudioService extends Service {
              * Incoming Call : Pause if VLC is playing audio or video. 
              */
             if (action.equalsIgnoreCase(VLCApplication.INCOMING_CALL_INTENT)) {
+                mWasPlayingAudio = mLibVLC.isPlaying() && mLibVLC.getVideoTracksCount() < 1;
                 if (mLibVLC.isPlaying())
                     pause();
             }
 
+            /*
+             * Call ended : Play only if VLC was playing audio.
+             */
+            if (action.equalsIgnoreCase(VLCApplication.CALL_ENDED_INTENT)
+                    && mWasPlayingAudio) {
+                play();
+            }
+
             // skip all headsets events if there is a call
             TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
             if (telManager != null && telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)
-- 
1.9.1



More information about the Android mailing list