convert PlayerHolder to Singleton, handle context within, bugfix ServiceConnection leak
- bugfix: have ServiceConnection created only once! - select the context within the PlayerHolder to start, stop, bind or unbind the service -> we have to make sure the Service is started AND stopped within the same context -> so let PlayerHolder be the one to select the context - remove removeListener() and replace the call with setListener(null) - Compatibility: use ContextCompat.startForegroundService instead of startService()
This commit is contained in:
parent
e7f5162593
commit
61a54d9a64
11 changed files with 98 additions and 76 deletions
|
|
@ -201,6 +201,7 @@ public final class VideoDetailFragment
|
|||
@Nullable
|
||||
private MainPlayer playerService;
|
||||
private Player player;
|
||||
private PlayerHolder playerHolder = PlayerHolder.getInstance();
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Service management
|
||||
|
|
@ -360,9 +361,9 @@ public final class VideoDetailFragment
|
|||
// Stop the service when user leaves the app with double back press
|
||||
// if video player is selected. Otherwise unbind
|
||||
if (activity.isFinishing() && isPlayerAvailable() && player.videoPlayerSelected()) {
|
||||
PlayerHolder.stopService(App.getApp());
|
||||
playerHolder.stopService();
|
||||
} else {
|
||||
PlayerHolder.removeListener();
|
||||
playerHolder.setListener(null);
|
||||
}
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
|
|
@ -660,10 +661,10 @@ public final class VideoDetailFragment
|
|||
});
|
||||
|
||||
setupBottomPlayer();
|
||||
if (!PlayerHolder.bound) {
|
||||
if (!playerHolder.bound) {
|
||||
setHeightThumbnail();
|
||||
} else {
|
||||
PlayerHolder.startService(App.getApp(), false, this);
|
||||
playerHolder.startService(false, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1097,7 +1098,7 @@ public final class VideoDetailFragment
|
|||
|
||||
// See UI changes while remote playQueue changes
|
||||
if (!isPlayerAvailable()) {
|
||||
PlayerHolder.startService(App.getApp(), false, this);
|
||||
playerHolder.startService(false, this);
|
||||
}
|
||||
|
||||
toggleFullscreenIfInFullscreenMode();
|
||||
|
|
@ -1123,7 +1124,7 @@ public final class VideoDetailFragment
|
|||
private void openNormalBackgroundPlayer(final boolean append) {
|
||||
// See UI changes while remote playQueue changes
|
||||
if (!isPlayerAvailable()) {
|
||||
PlayerHolder.startService(App.getApp(), false, this);
|
||||
playerHolder.startService(false, this);
|
||||
}
|
||||
|
||||
final PlayQueue queue = setupPlayQueueForIntent(append);
|
||||
|
|
@ -1137,7 +1138,7 @@ public final class VideoDetailFragment
|
|||
|
||||
private void openMainPlayer() {
|
||||
if (!isPlayerServiceAvailable()) {
|
||||
PlayerHolder.startService(App.getApp(), autoPlayEnabled, this);
|
||||
playerHolder.startService(autoPlayEnabled, this);
|
||||
return;
|
||||
}
|
||||
if (currentInfo == null) {
|
||||
|
|
@ -1155,7 +1156,7 @@ public final class VideoDetailFragment
|
|||
|
||||
final Intent playerIntent = NavigationHelper
|
||||
.getPlayerIntent(requireContext(), MainPlayer.class, queue, true, autoPlayEnabled);
|
||||
activity.startService(playerIntent);
|
||||
ContextCompat.startForegroundService(activity, playerIntent);
|
||||
}
|
||||
|
||||
private void hideMainPlayer() {
|
||||
|
|
@ -1373,9 +1374,9 @@ public final class VideoDetailFragment
|
|||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
// Rebound to the service if it was closed via notification or mini player
|
||||
if (!PlayerHolder.bound) {
|
||||
PlayerHolder.startService(
|
||||
App.getApp(), false, VideoDetailFragment.this);
|
||||
if (!playerHolder.bound) {
|
||||
playerHolder.startService(
|
||||
false, VideoDetailFragment.this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -2119,7 +2120,7 @@ public final class VideoDetailFragment
|
|||
if (currentWorker != null) {
|
||||
currentWorker.dispose();
|
||||
}
|
||||
PlayerHolder.stopService(App.getApp());
|
||||
playerHolder.stopService();
|
||||
setInitialData(0, null, "", null);
|
||||
currentInfo = null;
|
||||
updateOverlayData(null, null, null);
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
|
|||
|
||||
final List<StreamDialogEntry> entries = new ArrayList<>();
|
||||
|
||||
if (PlayerHolder.getType() != null) {
|
||||
if (PlayerHolder.getInstance().getType() != null) {
|
||||
entries.add(StreamDialogEntry.enqueue);
|
||||
}
|
||||
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
|||
|
||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||
|
||||
if (PlayerHolder.getType() != null) {
|
||||
if (PlayerHolder.getInstance().getType() != null) {
|
||||
entries.add(StreamDialogEntry.enqueue);
|
||||
}
|
||||
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue