android: Support play / pause from media session

This commit is contained in:
Colin Edwards 2024-01-13 23:15:56 -06:00
parent 380e0abbe4
commit 87873c9a73
3 changed files with 23 additions and 1 deletions

View File

@ -18,6 +18,7 @@ public class Bridge {
public static native void run(Context context, LogListener logListener);
public static native void shutdown();
public static native void pause();
public static native void playPause();
public static native void playNext();
public static native void playPrevious();
}

View File

@ -36,7 +36,11 @@ public class MPDPlayer extends SimpleBasePlayer {
@NonNull
@Override
protected State getState() {
Commands commands = new Commands.Builder().addAll(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM, COMMAND_SEEK_TO_NEXT_MEDIA_ITEM).build();
Commands commands = new Commands.Builder().addAll(
COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM,
COMMAND_SEEK_TO_NEXT_MEDIA_ITEM,
COMMAND_PLAY_PAUSE
).build();
return new State.Builder()
.setAvailableCommands(commands)
@ -46,6 +50,13 @@ public class MPDPlayer extends SimpleBasePlayer {
.build();
}
@NonNull
@Override
protected ListenableFuture<?> handleSetPlayWhenReady(boolean playWhenReady) {
Bridge.playPause();
return Futures.immediateVoidFuture();
}
@NonNull
@SuppressLint("SwitchIntDef")
@Override

View File

@ -614,6 +614,16 @@ Java_org_musicpd_Bridge_pause(JNIEnv *, jclass)
partition.pc.LockSetPause(true);
}
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_musicpd_Bridge_playPause(JNIEnv *, jclass)
{
if (global_instance != nullptr)
for (auto &partition : global_instance->partitions)
partition.pc.LockPause();
}
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_musicpd_Bridge_playNext(JNIEnv *, jclass)