1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-24 16:07:04 +00:00

PlayerHolder: inline bind

Only used once. Now the code looks weird … why is the service started
twice??
This commit is contained in:
Profpatsch 2024-12-26 00:26:22 +01:00
parent ef3c76645f
commit a78bed700a

View File

@ -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");