[Android] PlaybackService: send EFFECT_CONTROL_SESSION on media state update

Alexandre Janniaux git at videolan.org
Fri Feb 23 17:27:54 CET 2018


vlc-android | branch: master | Alexandre Janniaux <alexandre.janniaux at gmail.com> | Thu Feb 22 18:31:27 2018 +0100| [00316e7f12a603667cd6588ce74bb6a075166105] | committer: Geoffrey Métais

PlaybackService: send EFFECT_CONTROL_SESSION on media state update

Send the *_EFFECT_CONTROL_SESSION intent when the state of current media
is updated. It allows external audio effects like equalizer or
visualizer to know the audio session id used by VLC and apply their own
effect.
See android.media.audiofx.AudioEffect.

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/00316e7f12a603667cd6588ce74bb6a075166105
---

 .../src/org/videolan/vlc/PlaybackService.java      | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 9313d78c1..fa58444d9 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -35,6 +35,7 @@ import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.media.audiofx.AudioEffect;
 import android.media.AudioManager;
 import android.media.AudioManager.OnAudioFocusChangeListener;
 import android.net.Uri;
@@ -89,6 +90,7 @@ import org.videolan.vlc.util.Constants;
 import org.videolan.vlc.util.Permissions;
 import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCInstance;
+import org.videolan.vlc.util.VLCOptions;
 import org.videolan.vlc.util.VoiceSearchParams;
 import org.videolan.vlc.util.WeakHandler;
 import org.videolan.vlc.widget.VLCAppWidgetProvider;
@@ -375,6 +377,32 @@ public class PlaybackService extends MediaBrowserServiceCompat{
         };
     }
 
+    private void sendStartSessionIdIntent() {
+        int sessionId = VLCOptions.getAudiotrackSessionId();
+        if (sessionId == 0)
+            return;
+
+        Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
+        intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
+        intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
+        if (isVideoPlaying())
+            intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MOVIE);
+        else
+            intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
+        sendBroadcast(intent);
+    }
+
+    private void sendStopSessionIdIntent() {
+        int sessionId = VLCOptions.getAudiotrackSessionId();
+        if (sessionId == 0)
+            return;
+
+        Intent intent = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
+        intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
+        intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
+        sendBroadcast(intent);
+    }
+
     private AudioManager mAudioManager = null;
     private void changeAudioFocus(boolean acquire) {
         if (mAudioManager == null)
@@ -1053,9 +1081,17 @@ public class PlaybackService extends MediaBrowserServiceCompat{
         if (playlistManager.hasPlaylist())
             pscb.addCustomAction("shuffle", getString(R.string.shuffle_title), isShuffling() ? R.drawable.ic_auto_shuffle_pressed : R.drawable.ic_auto_shuffle_normal);
         pscb.addCustomAction("repeat", getString(R.string.repeat_title), repeatResId);
+
+        boolean mediaIsActive = state != PlaybackStateCompat.STATE_STOPPED;
+
         mMediaSession.setPlaybackState(pscb.build());
-        mMediaSession.setActive(state != PlaybackStateCompat.STATE_STOPPED);
+        mMediaSession.setActive(mediaIsActive);
         mMediaSession.setQueueTitle(getString(R.string.music_now_playing));
+
+        if (mediaIsActive)
+            sendStartSessionIdIntent();
+        else
+            sendStopSessionIdIntent();
     }
 
     private void notifyTrackChanged() {



More information about the Android mailing list