Skip to content

Commit a78bed7

Browse files
committed
PlayerHolder: inline bind
Only used once. Now the code looks weird … why is the service started twice??
1 parent ef3c766 commit a78bed7

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ private Context getCommonContext() {
123123
return App.getInstance();
124124
}
125125

126+
127+
/** Connect to (and if needed start) the {@link PlayerService}
128+
* and bind {@link PlayerServiceConnection} to it.
129+
* If the service is already started, only set the listener.
130+
* @param playAfterConnect If the service is started, start playing immediately
131+
* @param newListener set this listener
132+
* */
126133
public void startService(final boolean playAfterConnect,
127134
final PlayerServiceExtendedEventListener newListener) {
128135
final Context context = getCommonContext();
@@ -136,7 +143,17 @@ public void startService(final boolean playAfterConnect,
136143
unbind(context);
137144
ContextCompat.startForegroundService(context, new Intent(context, PlayerService.class));
138145
serviceConnection.playAfterConnect = playAfterConnect;
139-
bind(context);
146+
147+
if (DEBUG) {
148+
Log.d(TAG, "bind() called");
149+
}
150+
151+
final Intent serviceIntent = new Intent(context, PlayerService.class);
152+
bound = context.bindService(serviceIntent, serviceConnection,
153+
Context.BIND_AUTO_CREATE);
154+
if (!bound) {
155+
context.unbindService(serviceConnection);
156+
}
140157
}
141158

142159
public void stopService() {
@@ -178,23 +195,6 @@ public void onServiceConnected(final ComponentName compName, final IBinder servi
178195
}
179196
}
180197

181-
/** Connect to (and if needed start) the {@link PlayerService}
182-
* and bind {@link PlayerServiceConnection} to it.
183-
* @param context common holder context
184-
* */
185-
private void bind(final Context context) {
186-
if (DEBUG) {
187-
Log.d(TAG, "bind() called");
188-
}
189-
190-
final Intent serviceIntent = new Intent(context, PlayerService.class);
191-
bound = context.bindService(serviceIntent, serviceConnection,
192-
Context.BIND_AUTO_CREATE);
193-
if (!bound) {
194-
context.unbindService(serviceConnection);
195-
}
196-
}
197-
198198
private void unbind(final Context context) {
199199
if (DEBUG) {
200200
Log.d(TAG, "unbind() called");

0 commit comments

Comments
 (0)