mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Send MediaSessionAction from Android
This commit is contained in:
parent
b494acbf19
commit
08f9f17ed3
10 changed files with 64 additions and 15 deletions
|
@ -241,11 +241,11 @@ public class MainActivity extends Activity implements Servo.Client {
|
|||
mMediaSession = new MediaSession(mServoView, this, getApplicationContext());
|
||||
}
|
||||
Log.d("SERVOMEDIA", "PLAYBACK STATE CHANGED " + state);
|
||||
if (state == 1 /* none */) {
|
||||
if (state == MediaSession.PLAYBACK_STATE_NONE) {
|
||||
mMediaSession.hideMediaSessionControls();
|
||||
return;
|
||||
}
|
||||
if (state == 2 /* playing */) {
|
||||
if (state == MediaSession.PLAYBACK_STATE_PLAYING) {
|
||||
mMediaSession.showMediaSessionControls();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,22 @@ public class MediaSession {
|
|||
}
|
||||
}
|
||||
|
||||
// https://w3c.github.io/mediasession/#enumdef-mediasessionplaybackstate
|
||||
public static final int PLAYBACK_STATE_NONE = 1;
|
||||
public static final int PLAYBACK_STATE_PLAYING = 2;
|
||||
public static final int PLAYBACK_STATE_PAUSED = 3;
|
||||
|
||||
// https://w3c.github.io/mediasession/#enumdef-mediasessionaction
|
||||
private static final int ACTION_PLAY = 1;
|
||||
private static final int ACTION_PAUSE = 2;
|
||||
private static final int ACTON_SEEK_BACKWARD = 3;
|
||||
private static final int ACTION_SEEK_FORWARD = 4;
|
||||
private static final int ACTION_PREVIOUS_TRACK = 5;
|
||||
private static final int ACTION_NEXT_TRACK = 6;
|
||||
private static final int ACTION_SKIP_AD = 7;
|
||||
private static final int ACTION_STOP = 8;
|
||||
private static final int ACTION_SEEK_TO = 9;
|
||||
|
||||
private static final String MEDIA_CHANNEL_ID = "MediaNotificationChannel";
|
||||
private static final String KEY_MEDIA_PAUSE = "org.mozilla.servoview.MainActivity.pause";
|
||||
private static final String KEY_MEDIA_PREV = "org.mozilla.servoview.MainActivity.prev";
|
||||
|
@ -79,12 +95,16 @@ public class MediaSession {
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(KEY_MEDIA_PAUSE)) {
|
||||
mView.mediaSessionAction(ACTION_PAUSE);
|
||||
Log.d("SERVOMEDIA", "PAUSE");
|
||||
} else if (intent.getAction().equals(KEY_MEDIA_STOP)) {
|
||||
mView.mediaSessionAction(ACTION_STOP);
|
||||
Log.d("SERVOMEDIA", "STOP");
|
||||
} else if (intent.getAction().equals(KEY_MEDIA_NEXT)) {
|
||||
mView.mediaSessionAction(ACTION_NEXT_TRACK);
|
||||
Log.d("SERVOMEDIA", "NEXT");
|
||||
} else if (intent.getAction().equals(KEY_MEDIA_PREV)) {
|
||||
mView.mediaSessionAction(ACTION_PREVIOUS_TRACK);
|
||||
Log.d("SERVOMEDIA", "PREV");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@ public class JNIServo {
|
|||
|
||||
public native void click(float x, float y);
|
||||
|
||||
public native void mediaSessionAction(int action);
|
||||
|
||||
public static class ServoOptions {
|
||||
public String args;
|
||||
public String url;
|
||||
|
|
|
@ -168,6 +168,10 @@ public class Servo {
|
|||
mSuspended = suspended;
|
||||
}
|
||||
|
||||
public void mediaSessionAction(int action) {
|
||||
mRunCallback.inGLThread(() -> mJNI.mediaSessionAction(action));
|
||||
}
|
||||
|
||||
public interface Client {
|
||||
void onAlert(String message);
|
||||
|
||||
|
|
|
@ -134,8 +134,12 @@ public class ServoView extends GLSurfaceView
|
|||
}
|
||||
}
|
||||
|
||||
public void mediaSessionAction(int action) {
|
||||
mServo.mediaSessionAction(action);
|
||||
}
|
||||
|
||||
public void flushGLBuffers() {
|
||||
requestRender();
|
||||
requestRender();
|
||||
}
|
||||
|
||||
// Scroll and click
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue