[Android] AudioServiceController: add callbacks to signal when the connection to the audio service is ready

Adrien Maglo git at videolan.org
Mon Mar 10 09:18:29 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Mar 10 09:14:44 2014 +0100| [6a326921e159ee649df51d2554f5a4f71d56f9a3] | committer: Adrien Maglo

AudioServiceController: add callbacks to signal when the connection to the audio service is ready

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=6a326921e159ee649df51d2554f5a4f71d56f9a3
---

 .../org/videolan/vlc/AudioServiceController.java   |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/AudioServiceController.java b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
index 197c2ba..b444ba5 100644
--- a/vlc-android/src/org/videolan/vlc/AudioServiceController.java
+++ b/vlc-android/src/org/videolan/vlc/AudioServiceController.java
@@ -73,9 +73,21 @@ public class AudioServiceController implements IAudioPlayerControl {
     }
 
     /**
+     * The connection listener interface for the audio service
+     */
+    public interface AudioServiceConnectionListener {
+        public void onConnectionSuccess();
+        public void onConnectionFailed();
+    }
+
+    /**
      * Bind to audio service if it is running
      */
     public void bindAudioService(Context context) {
+        bindAudioService(context, null);
+    }
+
+    public void bindAudioService(Context context, final AudioServiceConnectionListener connectionListerner) {
         if (context == null) {
             Log.w(TAG, "bindAudioService() with null Context. Ooops" );
             return;
@@ -108,8 +120,12 @@ public class AudioServiceController implements IAudioPlayerControl {
                     try {
                         mAudioServiceBinder.addAudioCallback(mCallback);
                         mAudioServiceBinder.detectHeadset(enableHS);
+                        if (connectionListerner != null)
+                            connectionListerner.onConnectionSuccess();
                     } catch (RemoteException e) {
                         Log.e(TAG, "remote procedure call failed: addAudioCallback()");
+                        if (connectionListerner != null)
+                            connectionListerner.onConnectionFailed();
                     }
                     updateAudioPlayer();
                 }
@@ -121,8 +137,12 @@ public class AudioServiceController implements IAudioPlayerControl {
             try {
                 if (mAudioServiceBinder != null)
                     mAudioServiceBinder.addAudioCallback(mCallback);
+                if (connectionListerner != null)
+                    connectionListerner.onConnectionSuccess();
             } catch (RemoteException e) {
                 Log.e(TAG, "remote procedure call failed: addAudioCallback()");
+                if (connectionListerner != null)
+                    connectionListerner.onConnectionFailed();
             }
         }
     }



More information about the Android mailing list