mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-25 00:16:56 +00:00
PlayerHolder: inline bind
Only used once. Now the code looks weird … why is the service started twice??
This commit is contained in:
parent
ef3c76645f
commit
a78bed700a
@ -123,6 +123,13 @@ public final class PlayerHolder {
|
|||||||
return App.getInstance();
|
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,
|
public void startService(final boolean playAfterConnect,
|
||||||
final PlayerServiceExtendedEventListener newListener) {
|
final PlayerServiceExtendedEventListener newListener) {
|
||||||
final Context context = getCommonContext();
|
final Context context = getCommonContext();
|
||||||
@ -136,7 +143,17 @@ public final class PlayerHolder {
|
|||||||
unbind(context);
|
unbind(context);
|
||||||
ContextCompat.startForegroundService(context, new Intent(context, PlayerService.class));
|
ContextCompat.startForegroundService(context, new Intent(context, PlayerService.class));
|
||||||
serviceConnection.playAfterConnect = playAfterConnect;
|
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() {
|
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) {
|
private void unbind(final Context context) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "unbind() called");
|
Log.d(TAG, "unbind() called");
|
||||||
|
Loading…
Reference in New Issue
Block a user