aboutsummaryrefslogtreecommitdiff
path: root/tools/android
diff options
context:
space:
mode:
authorChris "Koying" Browet <cbro@semperpax.com>2017-01-13 17:37:16 +0100
committerChris "Koying" Browet <cbro@semperpax.com>2017-08-15 18:06:29 +0200
commit90f3ba068e819dbaf587f0775f4840f7ca5207c3 (patch)
treeee4de18ce5723e16a5edcc5fc852ce6c8166f345 /tools/android
parent2ce975ca6d91953a3af0e0ed75f0967ee7822504 (diff)
ADD: [droid] MediaSession handling (Now Playing)
Diffstat (limited to 'tools/android')
-rw-r--r--tools/android/packaging/xbmc/src/XBMCMediaSession.java.in143
1 files changed, 143 insertions, 0 deletions
diff --git a/tools/android/packaging/xbmc/src/XBMCMediaSession.java.in b/tools/android/packaging/xbmc/src/XBMCMediaSession.java.in
new file mode 100644
index 0000000000..0a78996e59
--- /dev/null
+++ b/tools/android/packaging/xbmc/src/XBMCMediaSession.java.in
@@ -0,0 +1,143 @@
+package @APP_PACKAGE@;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.media.MediaMetadata;
+import android.media.session.MediaSession;
+import android.media.session.PlaybackState;
+import android.util.Log;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+
+/**
+ * Created by Christian BROWET on 1/10/17.
+ */
+
+public class XBMCMediaSession
+{
+ native void _onPlayRequested();
+ native void _onPauseRequested();
+ native void _onNextRequested();
+ native void _onPreviousRequested();
+ native void _onForwardRequested();
+ native void _onRewindRequested();
+ native void _onStopRequested();
+ native void _onSeekRequested(long pos);
+
+ private static final String TAG = "XBMCMediaSession";
+
+ private class XBMCMediaSessionCallback extends MediaSession.Callback
+ {
+
+ @Override
+ public void onPlay()
+ {
+ Log.d(TAG, "onPlay: ");
+ super.onPlay();
+ _onPlayRequested();
+ }
+
+ @Override
+ public void onPause()
+ {
+ Log.d(TAG, "onPause: ");
+ super.onPause();
+ _onPauseRequested();
+ }
+
+ @Override
+ public void onSkipToNext()
+ {
+ Log.d(TAG, "onSkipToNext: ");
+ super.onSkipToNext();
+ _onNextRequested();
+ }
+
+ @Override
+ public void onSkipToPrevious()
+ {
+ Log.d(TAG, "onSkipToPrevious: ");
+ super.onSkipToPrevious();
+ _onPreviousRequested();
+ }
+
+ @Override
+ public void onFastForward()
+ {
+ Log.d(TAG, "onFastForward: ");
+ super.onFastForward();
+ _onForwardRequested();
+ }
+
+ @Override
+ public void onRewind()
+ {
+ Log.d(TAG, "onRewind: ");
+ super.onRewind();
+ _onRewindRequested();
+ }
+
+ @Override
+ public void onStop()
+ {
+ Log.d(TAG, "onStop: ");
+ super.onStop();
+ _onStopRequested();
+ }
+
+ @Override
+ public void onSeekTo(long pos)
+ {
+ Log.d(TAG, "onSeekTo: ");
+ super.onSeekTo(pos);
+ _onSeekRequested(pos);
+ }
+ }
+
+ private MediaSession mSession = null;
+ private XBMCMediaSessionCallback mMediaSessionCallback;
+ private long mTotDurMs = 0;
+
+ public XBMCMediaSession()
+ {
+ Log.d(TAG, "XBMCMediaSession init");
+ this.mSession = new MediaSession(Main.MainActivity, "XBMC_session");
+ this.mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
+
+ Main.MainActivity.runOnUiThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ Log.d(TAG, "XBMCMediaSession callback");
+ mMediaSessionCallback = new XBMCMediaSessionCallback();
+ mSession.setCallback(mMediaSessionCallback);
+ }
+ });
+ }
+
+ public void activate(boolean state)
+ {
+ mSession.setActive(state);
+ }
+
+ private void updatePlaybackState(PlaybackState mystate)
+ {
+ mSession.setPlaybackState(mystate);
+ }
+
+ private void updateMetadata(MediaMetadata myData)
+ {
+ mSession.setMetadata(myData);
+ }
+
+ private void updateIntent(Intent intent)
+ {
+ PendingIntent pi = PendingIntent.getActivity(Main.MainActivity, 99 /*request code*/,
+ intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ mSession.setSessionActivity(pi);
+ }
+
+}