mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2024-12-26 16:52:46 +01:00
Merge pull request #3994 from ByteHamster/rebind-service-after-stopping
Rebind to the service after it was stopped
This commit is contained in:
commit
67ef897e6b
@ -172,17 +172,10 @@ public class ExternalPlayerFragment extends Fragment {
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
disposable = Maybe.create(emitter -> {
|
||||
Playable media = controller.getMedia();
|
||||
if (media != null) {
|
||||
emitter.onSuccess(media);
|
||||
} else {
|
||||
emitter.onComplete();
|
||||
}
|
||||
})
|
||||
disposable = Maybe.fromCallable(() -> controller.getMedia())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> updateUi((Playable) media),
|
||||
.subscribe(this::updateUi,
|
||||
error -> Log.e(TAG, Log.getStackTraceString(error)),
|
||||
() -> ((MainActivity) getActivity()).setPlayerVisible(false));
|
||||
return true;
|
||||
|
@ -148,15 +148,7 @@ public class PlaybackController {
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
if(serviceBinder != null) {
|
||||
serviceBinder.dispose();
|
||||
}
|
||||
try {
|
||||
activity.unbindService(mConnection);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
unbind();
|
||||
|
||||
try {
|
||||
activity.unregisterReceiver(shutdownReceiver);
|
||||
@ -173,6 +165,18 @@ public class PlaybackController {
|
||||
}
|
||||
}
|
||||
|
||||
private void unbind() {
|
||||
if (serviceBinder != null) {
|
||||
serviceBinder.dispose();
|
||||
}
|
||||
try {
|
||||
activity.unbindService(mConnection);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be called in the activity's onPause() method.
|
||||
*/
|
||||
@ -256,6 +260,7 @@ public class PlaybackController {
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
playbackService = null;
|
||||
initialized = false;
|
||||
Log.d(TAG, "Disconnected from Service");
|
||||
}
|
||||
};
|
||||
@ -328,13 +333,11 @@ public class PlaybackController {
|
||||
};
|
||||
|
||||
private final BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (playbackService != null) {
|
||||
if (TextUtils.equals(intent.getAction(),
|
||||
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
|
||||
release();
|
||||
if (TextUtils.equals(intent.getAction(), PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
|
||||
unbind();
|
||||
onShutdownNotification();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user