From 0075c57bd4bd8e1a8bd9c254aa9ca990ac897fbf Mon Sep 17 00:00:00 2001
From: Colin Edwards <colin@recursivepenguin.com>
Date: Sat, 13 Jan 2024 23:19:31 -0600
Subject: [PATCH] android: Check playlist state before changing track

Playlist will throw an exception if we call next or previous track when it is not in the "playing" state
---
 src/Main.cxx | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/Main.cxx b/src/Main.cxx
index 6b10ff6d4..9840b8b62 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -621,7 +621,9 @@ Java_org_musicpd_Bridge_playNext(JNIEnv *, jclass)
 	if (global_instance != nullptr)
 		BlockingCall(global_instance->event_loop, [&](){
 			for (auto &partition : global_instance->partitions)
-				partition.PlayNext();
+				if (partition.playlist.playing) {
+					partition.PlayNext();
+				}
 		});
 }
 
@@ -632,7 +634,9 @@ Java_org_musicpd_Bridge_playPrevious(JNIEnv *, jclass)
 	if (global_instance != nullptr)
 		BlockingCall(global_instance->event_loop, [&](){
 			for (auto &partition : global_instance->partitions)
-				partition.PlayPrevious();
+				if (partition.playlist.playing) {
+					partition.PlayPrevious();
+				}
 		});
 }