From a78bed700aba3a52e732e8e6bc1e7477209b3a29 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Thu, 26 Dec 2024 00:26:22 +0100 Subject: [PATCH] PlayerHolder: inline `bind` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only used once. Now the code looks weird … why is the service started twice?? --- .../newpipe/player/helper/PlayerHolder.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java index 70a1da6a7..74b125178 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java @@ -123,6 +123,13 @@ public final class PlayerHolder { return App.getInstance(); } + + /** Connect to (and if needed start) the {@link PlayerService} + * and bind {@link PlayerServiceConnection} to it. + * If the service is already started, only set the listener. + * @param playAfterConnect If the service is started, start playing immediately + * @param newListener set this listener + * */ public void startService(final boolean playAfterConnect, final PlayerServiceExtendedEventListener newListener) { final Context context = getCommonContext(); @@ -136,7 +143,17 @@ public final class PlayerHolder { unbind(context); ContextCompat.startForegroundService(context, new Intent(context, PlayerService.class)); serviceConnection.playAfterConnect = playAfterConnect; - bind(context); + + if (DEBUG) { + Log.d(TAG, "bind() called"); + } + + final Intent serviceIntent = new Intent(context, PlayerService.class); + bound = context.bindService(serviceIntent, serviceConnection, + Context.BIND_AUTO_CREATE); + if (!bound) { + context.unbindService(serviceConnection); + } } public void stopService() { @@ -178,23 +195,6 @@ public final class PlayerHolder { } } - /** Connect to (and if needed start) the {@link PlayerService} - * and bind {@link PlayerServiceConnection} to it. - * @param context common holder context - * */ - private void bind(final Context context) { - if (DEBUG) { - Log.d(TAG, "bind() called"); - } - - final Intent serviceIntent = new Intent(context, PlayerService.class); - bound = context.bindService(serviceIntent, serviceConnection, - Context.BIND_AUTO_CREATE); - if (!bound) { - context.unbindService(serviceConnection); - } - } - private void unbind(final Context context) { if (DEBUG) { Log.d(TAG, "unbind() called");