From e086f09d48cd2187b995b75468a74241343cd5c2 Mon Sep 17 00:00:00 2001 From: Colin Edwards Date: Thu, 28 Dec 2023 22:46:59 -0600 Subject: [PATCH] android: add next and previous track to the jni bridge This will allow the android client to directly make calls to the mpd process to change tracks I went with camel case on the function names here, if you use an underscore javac generates a function tht looks like this: JNIEXPORT void JNICALL Java_org_musicpd_Bridge_play_1previous I figured what we ended up with looks a little nicer: JNIEXPORT void JNICALL Java_org_musicpd_Bridge_playPrevious --- .../app/src/main/java/org/musicpd/Bridge.java | 2 ++ src/Main.cxx | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/android/app/src/main/java/org/musicpd/Bridge.java b/android/app/src/main/java/org/musicpd/Bridge.java index 6ad49e2d4..0ca31ebe6 100644 --- a/android/app/src/main/java/org/musicpd/Bridge.java +++ b/android/app/src/main/java/org/musicpd/Bridge.java @@ -18,4 +18,6 @@ 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 playNext(); + public static native void playPrevious(); } diff --git a/src/Main.cxx b/src/Main.cxx index 4a469bc4f..e66e7f277 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -614,6 +614,28 @@ Java_org_musicpd_Bridge_pause(JNIEnv *, jclass) partition.pc.LockSetPause(true); } +gcc_visibility_default +JNIEXPORT void JNICALL +Java_org_musicpd_Bridge_playNext(JNIEnv *, jclass) +{ + if (global_instance != nullptr) + BlockingCall(global_instance->event_loop, [&](){ + for (auto &partition : global_instance->partitions) + partition.PlayNext(); + }); +} + +gcc_visibility_default +JNIEXPORT void JNICALL +Java_org_musicpd_Bridge_playPrevious(JNIEnv *, jclass) +{ + if (global_instance != nullptr) + BlockingCall(global_instance->event_loop, [&](){ + for (auto &partition : global_instance->partitions) + partition.PlayPrevious(); + }); +} + #else static inline void