mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 16:40:32 +00:00
Merge pull request #6566 from evermind-zz/various-fixes-for-upstream
Convert PlayerHolder to Singleton; cleanup in VideoDetailFragment; Player/MainPlayer do not call onDestroy() directly
This commit is contained in:
commit
14dab85ff0
@ -823,7 +823,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PlayerHolder.isPlayerOpen()) {
|
if (PlayerHolder.getInstance().isPlayerOpen()) {
|
||||||
// if the player is already open, no need for a broadcast receiver
|
// if the player is already open, no need for a broadcast receiver
|
||||||
openMiniPlayerIfMissing();
|
openMiniPlayerIfMissing();
|
||||||
} else {
|
} else {
|
||||||
|
@ -453,7 +453,7 @@ public class RouterActivity extends AppCompatActivity {
|
|||||||
returnList.add(showInfo);
|
returnList.add(showInfo);
|
||||||
returnList.add(videoPlayer);
|
returnList.add(videoPlayer);
|
||||||
} else {
|
} else {
|
||||||
final MainPlayer.PlayerType playerType = PlayerHolder.getType();
|
final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType();
|
||||||
if (capabilities.contains(VIDEO)
|
if (capabilities.contains(VIDEO)
|
||||||
&& PlayerHelper.isAutoplayAllowedByUser(context)
|
&& PlayerHelper.isAutoplayAllowedByUser(context)
|
||||||
&& playerType == null || playerType == MainPlayer.PlayerType.VIDEO) {
|
&& playerType == null || playerType == MainPlayer.PlayerType.VIDEO) {
|
||||||
|
@ -201,6 +201,7 @@ public final class VideoDetailFragment
|
|||||||
@Nullable
|
@Nullable
|
||||||
private MainPlayer playerService;
|
private MainPlayer playerService;
|
||||||
private Player player;
|
private Player player;
|
||||||
|
private PlayerHolder playerHolder = PlayerHolder.getInstance();
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Service management
|
// Service management
|
||||||
@ -304,7 +305,8 @@ public final class VideoDetailFragment
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
||||||
final Bundle savedInstanceState) {
|
final Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.fragment_video_detail, container, false);
|
binding = FragmentVideoDetailBinding.inflate(inflater, container, false);
|
||||||
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -355,14 +357,13 @@ public final class VideoDetailFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
binding = null;
|
|
||||||
|
|
||||||
// Stop the service when user leaves the app with double back press
|
// Stop the service when user leaves the app with double back press
|
||||||
// if video player is selected. Otherwise unbind
|
// if video player is selected. Otherwise unbind
|
||||||
if (activity.isFinishing() && player != null && player.videoPlayerSelected()) {
|
if (activity.isFinishing() && isPlayerAvailable() && player.videoPlayerSelected()) {
|
||||||
PlayerHolder.stopService(App.getApp());
|
playerHolder.stopService();
|
||||||
} else {
|
} else {
|
||||||
PlayerHolder.removeListener();
|
playerHolder.setListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(activity)
|
PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
@ -388,6 +389,12 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
binding = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
@ -512,7 +519,7 @@ public final class VideoDetailFragment
|
|||||||
openVideoPlayer();
|
openVideoPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
setOverlayPlayPauseImage(player != null && player.isPlaying());
|
setOverlayPlayPauseImage(isPlayerAvailable() && player.isPlaying());
|
||||||
break;
|
break;
|
||||||
case R.id.overlay_close_button:
|
case R.id.overlay_close_button:
|
||||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
@ -586,10 +593,9 @@ public final class VideoDetailFragment
|
|||||||
// Init
|
// Init
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@Override
|
@Override // called from onViewCreated in {@link BaseFragment#onViewCreated}
|
||||||
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
protected void initViews(final View rootView, final Bundle savedInstanceState) {
|
||||||
super.initViews(rootView, savedInstanceState);
|
super.initViews(rootView, savedInstanceState);
|
||||||
binding = FragmentVideoDetailBinding.bind(rootView);
|
|
||||||
|
|
||||||
pageAdapter = new TabAdapter(getChildFragmentManager());
|
pageAdapter = new TabAdapter(getChildFragmentManager());
|
||||||
binding.viewPager.setAdapter(pageAdapter);
|
binding.viewPager.setAdapter(pageAdapter);
|
||||||
@ -655,10 +661,10 @@ public final class VideoDetailFragment
|
|||||||
});
|
});
|
||||||
|
|
||||||
setupBottomPlayer();
|
setupBottomPlayer();
|
||||||
if (!PlayerHolder.bound) {
|
if (!playerHolder.bound) {
|
||||||
setHeightThumbnail();
|
setHeightThumbnail();
|
||||||
} else {
|
} else {
|
||||||
PlayerHolder.startService(App.getApp(), false, this);
|
playerHolder.startService(false, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,7 +727,7 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(final int keyCode) {
|
public boolean onKeyDown(final int keyCode) {
|
||||||
return player != null && player.onKeyDown(keyCode);
|
return isPlayerAvailable() && player.onKeyDown(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -731,7 +737,7 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we are in fullscreen mode just exit from it via first back press
|
// If we are in fullscreen mode just exit from it via first back press
|
||||||
if (player != null && player.isFullscreen()) {
|
if (isPlayerAvailable() && player.isFullscreen()) {
|
||||||
if (!DeviceUtils.isTablet(activity)) {
|
if (!DeviceUtils.isTablet(activity)) {
|
||||||
player.pause();
|
player.pause();
|
||||||
}
|
}
|
||||||
@ -741,7 +747,7 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have something in history of played items we replay it here
|
// If we have something in history of played items we replay it here
|
||||||
if (player != null
|
if (isPlayerAvailable()
|
||||||
&& player.getPlayQueue() != null
|
&& player.getPlayQueue() != null
|
||||||
&& player.videoPlayerSelected()
|
&& player.videoPlayerSelected()
|
||||||
&& player.getPlayQueue().previous()) {
|
&& player.getPlayQueue().previous()) {
|
||||||
@ -778,7 +784,7 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
final PlayQueueItem playQueueItem = item.getPlayQueue().getItem();
|
final PlayQueueItem playQueueItem = item.getPlayQueue().getItem();
|
||||||
// Update title, url, uploader from the last item in the stack (it's current now)
|
// Update title, url, uploader from the last item in the stack (it's current now)
|
||||||
final boolean isPlayerStopped = player == null || player.isStopped();
|
final boolean isPlayerStopped = !isPlayerAvailable() || player.isStopped();
|
||||||
if (playQueueItem != null && isPlayerStopped) {
|
if (playQueueItem != null && isPlayerStopped) {
|
||||||
updateOverlayData(playQueueItem.getTitle(),
|
updateOverlayData(playQueueItem.getTitle(),
|
||||||
playQueueItem.getUploader(), playQueueItem.getThumbnailUrl());
|
playQueueItem.getUploader(), playQueueItem.getThumbnailUrl());
|
||||||
@ -806,7 +812,7 @@ public final class VideoDetailFragment
|
|||||||
@Nullable final String newUrl,
|
@Nullable final String newUrl,
|
||||||
@NonNull final String newTitle,
|
@NonNull final String newTitle,
|
||||||
@Nullable final PlayQueue newQueue) {
|
@Nullable final PlayQueue newQueue) {
|
||||||
if (player != null && newQueue != null && playQueue != null
|
if (isPlayerAvailable() && newQueue != null && playQueue != null
|
||||||
&& !Objects.equals(newQueue.getItem(), playQueue.getItem())) {
|
&& !Objects.equals(newQueue.getItem(), playQueue.getItem())) {
|
||||||
// Preloading can be disabled since playback is surely being replaced.
|
// Preloading can be disabled since playback is surely being replaced.
|
||||||
player.disablePreloadingOfCurrentTrack();
|
player.disablePreloadingOfCurrentTrack();
|
||||||
@ -982,7 +988,7 @@ public final class VideoDetailFragment
|
|||||||
.replace(R.id.relatedItemsLayout, RelatedItemsFragment.getInstance(info))
|
.replace(R.id.relatedItemsLayout, RelatedItemsFragment.getInstance(info))
|
||||||
.commitAllowingStateLoss();
|
.commitAllowingStateLoss();
|
||||||
binding.relatedItemsLayout.setVisibility(
|
binding.relatedItemsLayout.setVisibility(
|
||||||
player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
|
isPlayerAvailable() && player.isFullscreen() ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1059,6 +1065,14 @@ public final class VideoDetailFragment
|
|||||||
// Play Utils
|
// Play Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
private void toggleFullscreenIfInFullscreenMode() {
|
||||||
|
// If a user watched video inside fullscreen mode and than chose another player
|
||||||
|
// return to non-fullscreen mode
|
||||||
|
if (isPlayerAvailable() && player.isFullscreen()) {
|
||||||
|
player.toggleFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void openBackgroundPlayer(final boolean append) {
|
private void openBackgroundPlayer(final boolean append) {
|
||||||
final AudioStream audioStream = currentInfo.getAudioStreams()
|
final AudioStream audioStream = currentInfo.getAudioStreams()
|
||||||
.get(ListHelper.getDefaultAudioFormat(activity, currentInfo.getAudioStreams()));
|
.get(ListHelper.getDefaultAudioFormat(activity, currentInfo.getAudioStreams()));
|
||||||
@ -1067,11 +1081,7 @@ public final class VideoDetailFragment
|
|||||||
.getDefaultSharedPreferences(activity)
|
.getDefaultSharedPreferences(activity)
|
||||||
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
|
.getBoolean(activity.getString(R.string.use_external_audio_player_key), false);
|
||||||
|
|
||||||
// If a user watched video inside fullscreen mode and than chose another player
|
toggleFullscreenIfInFullscreenMode();
|
||||||
// return to non-fullscreen mode
|
|
||||||
if (player != null && player.isFullscreen()) {
|
|
||||||
player.toggleFullscreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!useExternalAudioPlayer) {
|
if (!useExternalAudioPlayer) {
|
||||||
openNormalBackgroundPlayer(append);
|
openNormalBackgroundPlayer(append);
|
||||||
@ -1087,15 +1097,11 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See UI changes while remote playQueue changes
|
// See UI changes while remote playQueue changes
|
||||||
if (player == null) {
|
if (!isPlayerAvailable()) {
|
||||||
PlayerHolder.startService(App.getApp(), false, this);
|
playerHolder.startService(false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a user watched video inside fullscreen mode and than chose another player
|
toggleFullscreenIfInFullscreenMode();
|
||||||
// return to non-fullscreen mode
|
|
||||||
if (player != null && player.isFullscreen()) {
|
|
||||||
player.toggleFullscreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
final PlayQueue queue = setupPlayQueueForIntent(append);
|
final PlayQueue queue = setupPlayQueueForIntent(append);
|
||||||
if (append) {
|
if (append) {
|
||||||
@ -1117,8 +1123,8 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
private void openNormalBackgroundPlayer(final boolean append) {
|
private void openNormalBackgroundPlayer(final boolean append) {
|
||||||
// See UI changes while remote playQueue changes
|
// See UI changes while remote playQueue changes
|
||||||
if (player == null) {
|
if (!isPlayerAvailable()) {
|
||||||
PlayerHolder.startService(App.getApp(), false, this);
|
playerHolder.startService(false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayQueue queue = setupPlayQueueForIntent(append);
|
final PlayQueue queue = setupPlayQueueForIntent(append);
|
||||||
@ -1131,8 +1137,8 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openMainPlayer() {
|
private void openMainPlayer() {
|
||||||
if (playerService == null) {
|
if (!isPlayerServiceAvailable()) {
|
||||||
PlayerHolder.startService(App.getApp(), autoPlayEnabled, this);
|
playerHolder.startService(autoPlayEnabled, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentInfo == null) {
|
if (currentInfo == null) {
|
||||||
@ -1150,11 +1156,11 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
final Intent playerIntent = NavigationHelper
|
final Intent playerIntent = NavigationHelper
|
||||||
.getPlayerIntent(requireContext(), MainPlayer.class, queue, true, autoPlayEnabled);
|
.getPlayerIntent(requireContext(), MainPlayer.class, queue, true, autoPlayEnabled);
|
||||||
activity.startService(playerIntent);
|
ContextCompat.startForegroundService(activity, playerIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideMainPlayer() {
|
private void hideMainPlayer() {
|
||||||
if (playerService == null
|
if (!isPlayerServiceAvailable()
|
||||||
|| playerService.getView() == null
|
|| playerService.getView() == null
|
||||||
|| !player.videoPlayerSelected()) {
|
|| !player.videoPlayerSelected()) {
|
||||||
return;
|
return;
|
||||||
@ -1211,13 +1217,13 @@ public final class VideoDetailFragment
|
|||||||
private boolean isAutoplayEnabled() {
|
private boolean isAutoplayEnabled() {
|
||||||
return autoPlayEnabled
|
return autoPlayEnabled
|
||||||
&& !isExternalPlayerEnabled()
|
&& !isExternalPlayerEnabled()
|
||||||
&& (player == null || player.videoPlayerSelected())
|
&& (!isPlayerAvailable() || player.videoPlayerSelected())
|
||||||
&& bottomSheetState != BottomSheetBehavior.STATE_HIDDEN
|
&& bottomSheetState != BottomSheetBehavior.STATE_HIDDEN
|
||||||
&& PlayerHelper.isAutoplayAllowedByUser(requireContext());
|
&& PlayerHelper.isAutoplayAllowedByUser(requireContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVideoPlayerView() {
|
private void addVideoPlayerView() {
|
||||||
if (player == null || getView() == null) {
|
if (!isPlayerAvailable() || getView() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1277,7 +1283,7 @@ public final class VideoDetailFragment
|
|||||||
final boolean isPortrait = metrics.heightPixels > metrics.widthPixels;
|
final boolean isPortrait = metrics.heightPixels > metrics.widthPixels;
|
||||||
requireView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener);
|
requireView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener);
|
||||||
|
|
||||||
if (player != null && player.isFullscreen()) {
|
if (isPlayerAvailable() && player.isFullscreen()) {
|
||||||
final int height = (isInMultiWindow()
|
final int height = (isInMultiWindow()
|
||||||
? requireView()
|
? requireView()
|
||||||
: activity.getWindow().getDecorView()).getHeight();
|
: activity.getWindow().getDecorView()).getHeight();
|
||||||
@ -1300,7 +1306,7 @@ public final class VideoDetailFragment
|
|||||||
new FrameLayout.LayoutParams(
|
new FrameLayout.LayoutParams(
|
||||||
RelativeLayout.LayoutParams.MATCH_PARENT, newHeight));
|
RelativeLayout.LayoutParams.MATCH_PARENT, newHeight));
|
||||||
binding.detailThumbnailImageView.setMinimumHeight(newHeight);
|
binding.detailThumbnailImageView.setMinimumHeight(newHeight);
|
||||||
if (player != null) {
|
if (isPlayerAvailable()) {
|
||||||
final int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT);
|
final int maxHeight = (int) (metrics.heightPixels * MAX_PLAYER_HEIGHT);
|
||||||
player.getSurfaceView()
|
player.getSurfaceView()
|
||||||
.setHeights(newHeight, player.isFullscreen() ? newHeight : maxHeight);
|
.setHeights(newHeight, player.isFullscreen() ? newHeight : maxHeight);
|
||||||
@ -1368,9 +1374,9 @@ public final class VideoDetailFragment
|
|||||||
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||||
}
|
}
|
||||||
// Rebound to the service if it was closed via notification or mini player
|
// Rebound to the service if it was closed via notification or mini player
|
||||||
if (!PlayerHolder.bound) {
|
if (!playerHolder.bound) {
|
||||||
PlayerHolder.startService(
|
playerHolder.startService(
|
||||||
App.getApp(), false, VideoDetailFragment.this);
|
false, VideoDetailFragment.this);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1389,13 +1395,12 @@ public final class VideoDetailFragment
|
|||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
private void restoreDefaultOrientation() {
|
private void restoreDefaultOrientation() {
|
||||||
if (player == null || !player.videoPlayerSelected() || activity == null) {
|
if (!isPlayerAvailable() || !player.videoPlayerSelected() || activity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player != null && player.isFullscreen()) {
|
toggleFullscreenIfInFullscreenMode();
|
||||||
player.toggleFullscreen();
|
|
||||||
}
|
|
||||||
// This will show systemUI and pause the player.
|
// This will show systemUI and pause the player.
|
||||||
// User can tap on Play button and video will be in fullscreen mode again
|
// User can tap on Play button and video will be in fullscreen mode again
|
||||||
// Note for tablet: trying to avoid orientation changes since it's not easy
|
// Note for tablet: trying to avoid orientation changes since it's not easy
|
||||||
@ -1435,7 +1440,7 @@ public final class VideoDetailFragment
|
|||||||
if (binding.relatedItemsLayout != null) {
|
if (binding.relatedItemsLayout != null) {
|
||||||
if (showRelatedItems) {
|
if (showRelatedItems) {
|
||||||
binding.relatedItemsLayout.setVisibility(
|
binding.relatedItemsLayout.setVisibility(
|
||||||
player != null && player.isFullscreen() ? View.GONE : View.INVISIBLE);
|
isPlayerAvailable() && player.isFullscreen() ? View.GONE : View.INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
binding.relatedItemsLayout.setVisibility(View.GONE);
|
binding.relatedItemsLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
@ -1549,7 +1554,7 @@ public final class VideoDetailFragment
|
|||||||
showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView,
|
showMetaInfoInTextView(info.getMetaInfo(), binding.detailMetaInfoTextView,
|
||||||
binding.detailMetaInfoSeparator, disposables);
|
binding.detailMetaInfoSeparator, disposables);
|
||||||
|
|
||||||
if (player == null || player.isStopped()) {
|
if (!isPlayerAvailable() || player.isStopped()) {
|
||||||
updateOverlayData(info.getName(), info.getUploaderName(), info.getThumbnailUrl());
|
updateOverlayData(info.getName(), info.getUploaderName(), info.getThumbnailUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1812,9 +1817,7 @@ public final class VideoDetailFragment
|
|||||||
if (error.type == ExoPlaybackException.TYPE_SOURCE
|
if (error.type == ExoPlaybackException.TYPE_SOURCE
|
||||||
|| error.type == ExoPlaybackException.TYPE_UNEXPECTED) {
|
|| error.type == ExoPlaybackException.TYPE_UNEXPECTED) {
|
||||||
// Properly exit from fullscreen
|
// Properly exit from fullscreen
|
||||||
if (playerService != null && player.isFullscreen()) {
|
toggleFullscreenIfInFullscreenMode();
|
||||||
player.toggleFullscreen();
|
|
||||||
}
|
|
||||||
hideMainPlayer();
|
hideMainPlayer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1832,7 +1835,9 @@ public final class VideoDetailFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onFullscreenStateChanged(final boolean fullscreen) {
|
public void onFullscreenStateChanged(final boolean fullscreen) {
|
||||||
setupBrightness();
|
setupBrightness();
|
||||||
if (playerService.getView() == null || player.getParentActivity() == null) {
|
if (!isPlayerAndPlayerServiceAvailable()
|
||||||
|
|| playerService.getView() == null
|
||||||
|
|| player.getParentActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1955,7 +1960,7 @@ public final class VideoDetailFragment
|
|||||||
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
|
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
||||||
&& (isInMultiWindow() || (player != null && player.isFullscreen()))) {
|
&& (isInMultiWindow() || (isPlayerAvailable() && player.isFullscreen()))) {
|
||||||
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
|
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||||
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
|
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
|
||||||
}
|
}
|
||||||
@ -1964,7 +1969,7 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
// Listener implementation
|
// Listener implementation
|
||||||
public void hideSystemUiIfNeeded() {
|
public void hideSystemUiIfNeeded() {
|
||||||
if (player != null
|
if (isPlayerAvailable()
|
||||||
&& player.isFullscreen()
|
&& player.isFullscreen()
|
||||||
&& bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
&& bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
hideSystemUi();
|
hideSystemUi();
|
||||||
@ -1972,7 +1977,7 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean playerIsNotStopped() {
|
private boolean playerIsNotStopped() {
|
||||||
return player != null && !player.isStopped();
|
return isPlayerAvailable() && !player.isStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreDefaultBrightness() {
|
private void restoreDefaultBrightness() {
|
||||||
@ -1993,7 +1998,7 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
final WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
|
final WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
|
||||||
if (player == null
|
if (!isPlayerAvailable()
|
||||||
|| !player.videoPlayerSelected()
|
|| !player.videoPlayerSelected()
|
||||||
|| !player.isFullscreen()
|
|| !player.isFullscreen()
|
||||||
|| bottomSheetState != BottomSheetBehavior.STATE_EXPANDED) {
|
|| bottomSheetState != BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
@ -2059,7 +2064,7 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void replaceQueueIfUserConfirms(final Runnable onAllow) {
|
private void replaceQueueIfUserConfirms(final Runnable onAllow) {
|
||||||
@Nullable final PlayQueue activeQueue = player == null ? null : player.getPlayQueue();
|
@Nullable final PlayQueue activeQueue = isPlayerAvailable() ? player.getPlayQueue() : null;
|
||||||
|
|
||||||
// Player will have STATE_IDLE when a user pressed back button
|
// Player will have STATE_IDLE when a user pressed back button
|
||||||
if (isClearingQueueConfirmationRequired(activity)
|
if (isClearingQueueConfirmationRequired(activity)
|
||||||
@ -2115,7 +2120,7 @@ public final class VideoDetailFragment
|
|||||||
if (currentWorker != null) {
|
if (currentWorker != null) {
|
||||||
currentWorker.dispose();
|
currentWorker.dispose();
|
||||||
}
|
}
|
||||||
PlayerHolder.stopService(App.getApp());
|
playerHolder.stopService();
|
||||||
setInitialData(0, null, "", null);
|
setInitialData(0, null, "", null);
|
||||||
currentInfo = null;
|
currentInfo = null;
|
||||||
updateOverlayData(null, null, null);
|
updateOverlayData(null, null, null);
|
||||||
@ -2219,7 +2224,7 @@ public final class VideoDetailFragment
|
|||||||
hideSystemUiIfNeeded();
|
hideSystemUiIfNeeded();
|
||||||
// Conditions when the player should be expanded to fullscreen
|
// Conditions when the player should be expanded to fullscreen
|
||||||
if (isLandscape()
|
if (isLandscape()
|
||||||
&& player != null
|
&& isPlayerAvailable()
|
||||||
&& player.isPlaying()
|
&& player.isPlaying()
|
||||||
&& !player.isFullscreen()
|
&& !player.isFullscreen()
|
||||||
&& !DeviceUtils.isTablet(activity)
|
&& !DeviceUtils.isTablet(activity)
|
||||||
@ -2236,17 +2241,17 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
// Re-enable clicks
|
// Re-enable clicks
|
||||||
setOverlayElementsClickable(true);
|
setOverlayElementsClickable(true);
|
||||||
if (player != null) {
|
if (isPlayerAvailable()) {
|
||||||
player.closeItemsList();
|
player.closeItemsList();
|
||||||
}
|
}
|
||||||
setOverlayLook(binding.appBarLayout, behavior, 0);
|
setOverlayLook(binding.appBarLayout, behavior, 0);
|
||||||
break;
|
break;
|
||||||
case BottomSheetBehavior.STATE_DRAGGING:
|
case BottomSheetBehavior.STATE_DRAGGING:
|
||||||
case BottomSheetBehavior.STATE_SETTLING:
|
case BottomSheetBehavior.STATE_SETTLING:
|
||||||
if (player != null && player.isFullscreen()) {
|
if (isPlayerAvailable() && player.isFullscreen()) {
|
||||||
showSystemUi();
|
showSystemUi();
|
||||||
}
|
}
|
||||||
if (player != null && player.isControlsVisible()) {
|
if (isPlayerAvailable() && player.isControlsVisible()) {
|
||||||
player.hideControls(0, 0);
|
player.hideControls(0, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2310,4 +2315,17 @@ public final class VideoDetailFragment
|
|||||||
binding.overlayPlayPauseButton.setClickable(enable);
|
binding.overlayPlayPauseButton.setClickable(enable);
|
||||||
binding.overlayCloseButton.setClickable(enable);
|
binding.overlayCloseButton.setClickable(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helpers to check the state of player and playerService
|
||||||
|
boolean isPlayerAvailable() {
|
||||||
|
return (player != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPlayerServiceAvailable() {
|
||||||
|
return (playerService != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPlayerAndPlayerServiceAvailable() {
|
||||||
|
return (player != null && playerService != null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
|
|
||||||
final List<StreamDialogEntry> entries = new ArrayList<>();
|
final List<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getType() != null) {
|
if (PlayerHolder.getInstance().getType() != null) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
}
|
}
|
||||||
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
|
@ -144,7 +144,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
|
|||||||
|
|
||||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getType() != null) {
|
if (PlayerHolder.getInstance().getType() != null) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
}
|
}
|
||||||
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (item.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
|
@ -331,7 +331,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
if (context == null || context.resources == null || activity == null) return
|
if (context == null || context.resources == null || activity == null) return
|
||||||
|
|
||||||
val entries = ArrayList<StreamDialogEntry>()
|
val entries = ArrayList<StreamDialogEntry>()
|
||||||
if (PlayerHolder.getType() != null) {
|
if (PlayerHolder.getInstance().getType() != null) {
|
||||||
entries.add(StreamDialogEntry.enqueue)
|
entries.add(StreamDialogEntry.enqueue)
|
||||||
}
|
}
|
||||||
if (item.streamType == StreamType.AUDIO_STREAM) {
|
if (item.streamType == StreamType.AUDIO_STREAM) {
|
||||||
|
@ -340,7 +340,7 @@ public class StatisticsPlaylistFragment
|
|||||||
|
|
||||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getType() != null) {
|
if (PlayerHolder.getInstance().getType() != null) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
}
|
}
|
||||||
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
|
@ -749,7 +749,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
|||||||
|
|
||||||
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
final ArrayList<StreamDialogEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if (PlayerHolder.getType() != null) {
|
if (PlayerHolder.getInstance().getType() != null) {
|
||||||
entries.add(StreamDialogEntry.enqueue);
|
entries.add(StreamDialogEntry.enqueue);
|
||||||
}
|
}
|
||||||
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
if (infoItem.getStreamType() == StreamType.AUDIO_STREAM) {
|
||||||
|
@ -178,7 +178,10 @@ public final class MainPlayer extends Service {
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "destroy() called");
|
Log.d(TAG, "destroy() called");
|
||||||
}
|
}
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanup() {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
// Exit from fullscreen when user closes the player via notification
|
// Exit from fullscreen when user closes the player via notification
|
||||||
if (player.isFullscreen()) {
|
if (player.isFullscreen()) {
|
||||||
@ -191,9 +194,14 @@ public final class MainPlayer extends Service {
|
|||||||
player.stopActivityBinding();
|
player.stopActivityBinding();
|
||||||
player.removePopupFromView();
|
player.removePopupFromView();
|
||||||
player.destroy();
|
player.destroy();
|
||||||
}
|
|
||||||
|
|
||||||
|
player = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopService() {
|
||||||
NotificationUtil.getInstance().cancelNotificationAndStopForeground(this);
|
NotificationUtil.getInstance().cancelNotificationAndStopForeground(this);
|
||||||
|
cleanup();
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ public final class Player implements
|
|||||||
Log.d(TAG, "onPlaybackShutdown() called");
|
Log.d(TAG, "onPlaybackShutdown() called");
|
||||||
}
|
}
|
||||||
// destroys the service, which in turn will destroy the player
|
// destroys the service, which in turn will destroy the player
|
||||||
service.onDestroy();
|
service.stopService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void smoothStopPlayer() {
|
public void smoothStopPlayer() {
|
||||||
@ -1097,7 +1097,7 @@ public final class Player implements
|
|||||||
pause();
|
pause();
|
||||||
break;
|
break;
|
||||||
case ACTION_CLOSE:
|
case ACTION_CLOSE:
|
||||||
service.onDestroy();
|
service.stopService();
|
||||||
break;
|
break;
|
||||||
case ACTION_PLAY_PAUSE:
|
case ACTION_PLAY_PAUSE:
|
||||||
playPause();
|
playPause();
|
||||||
@ -1498,7 +1498,7 @@ public final class Player implements
|
|||||||
Objects.requireNonNull(windowManager)
|
Objects.requireNonNull(windowManager)
|
||||||
.removeView(closeOverlayBinding.getRoot());
|
.removeView(closeOverlayBinding.getRoot());
|
||||||
closeOverlayBinding = null;
|
closeOverlayBinding = null;
|
||||||
service.onDestroy();
|
service.stopService();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import android.os.IBinder;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
import com.google.android.exoplayer2.PlaybackParameters;
|
||||||
@ -22,18 +23,27 @@ import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
|
|||||||
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
||||||
|
|
||||||
public final class PlayerHolder {
|
public final class PlayerHolder {
|
||||||
|
|
||||||
private PlayerHolder() {
|
private PlayerHolder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean DEBUG = MainActivity.DEBUG;
|
private static PlayerHolder instance;
|
||||||
private static final String TAG = "PlayerHolder";
|
public static synchronized PlayerHolder getInstance() {
|
||||||
|
if (PlayerHolder.instance == null) {
|
||||||
|
PlayerHolder.instance = new PlayerHolder();
|
||||||
|
}
|
||||||
|
return PlayerHolder.instance;
|
||||||
|
}
|
||||||
|
|
||||||
private static PlayerServiceExtendedEventListener listener;
|
private final boolean DEBUG = MainActivity.DEBUG;
|
||||||
|
private final String TAG = PlayerHolder.class.getSimpleName();
|
||||||
|
|
||||||
private static ServiceConnection serviceConnection;
|
private PlayerServiceExtendedEventListener listener;
|
||||||
public static boolean bound;
|
|
||||||
private static MainPlayer playerService;
|
private final PlayerServiceConnection serviceConnection = new PlayerServiceConnection();
|
||||||
private static Player player;
|
public boolean bound;
|
||||||
|
private MainPlayer playerService;
|
||||||
|
private Player player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current {@link MainPlayer.PlayerType} of the {@link MainPlayer} service,
|
* Returns the current {@link MainPlayer.PlayerType} of the {@link MainPlayer} service,
|
||||||
@ -42,26 +52,31 @@ public final class PlayerHolder {
|
|||||||
* @return Current PlayerType
|
* @return Current PlayerType
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static MainPlayer.PlayerType getType() {
|
public MainPlayer.PlayerType getType() {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return player.getPlayerType();
|
return player.getPlayerType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return player.isPlaying();
|
return player.isPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlayerOpen() {
|
public boolean isPlayerOpen() {
|
||||||
return player != null;
|
return player != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setListener(final PlayerServiceExtendedEventListener newListener) {
|
public void setListener(@Nullable final PlayerServiceExtendedEventListener newListener) {
|
||||||
listener = newListener;
|
listener = newListener;
|
||||||
|
|
||||||
|
if (listener == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Force reload data from service
|
// Force reload data from service
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
listener.onServiceConnected(player, playerService, false);
|
listener.onServiceConnected(player, playerService, false);
|
||||||
@ -69,14 +84,15 @@ public final class PlayerHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeListener() {
|
// helper to handle context in common place as using the same
|
||||||
listener = null;
|
// context to bind/unbind a service is crucial
|
||||||
|
private Context getCommonContext() {
|
||||||
|
return App.getApp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void startService(final boolean playAfterConnect,
|
||||||
public static void startService(final Context context,
|
final PlayerServiceExtendedEventListener newListener) {
|
||||||
final boolean playAfterConnect,
|
final Context context = getCommonContext();
|
||||||
final PlayerServiceExtendedEventListener newListener) {
|
|
||||||
setListener(newListener);
|
setListener(newListener);
|
||||||
if (bound) {
|
if (bound) {
|
||||||
return;
|
return;
|
||||||
@ -85,58 +101,65 @@ public final class PlayerHolder {
|
|||||||
// and NullPointerExceptions inside the service because the service will be
|
// and NullPointerExceptions inside the service because the service will be
|
||||||
// bound twice. Prevent it with unbinding first
|
// bound twice. Prevent it with unbinding first
|
||||||
unbind(context);
|
unbind(context);
|
||||||
context.startService(new Intent(context, MainPlayer.class));
|
ContextCompat.startForegroundService(context, new Intent(context, MainPlayer.class));
|
||||||
serviceConnection = getServiceConnection(context, playAfterConnect);
|
serviceConnection.doPlayAfterConnect(playAfterConnect);
|
||||||
bind(context);
|
bind(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stopService(final Context context) {
|
public void stopService() {
|
||||||
|
final Context context = getCommonContext();
|
||||||
unbind(context);
|
unbind(context);
|
||||||
context.stopService(new Intent(context, MainPlayer.class));
|
context.stopService(new Intent(context, MainPlayer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ServiceConnection getServiceConnection(final Context context,
|
class PlayerServiceConnection implements ServiceConnection {
|
||||||
final boolean playAfterConnect) {
|
|
||||||
return new ServiceConnection() {
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(final ComponentName compName) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "Player service is disconnected");
|
|
||||||
}
|
|
||||||
|
|
||||||
unbind(context);
|
private boolean playAfterConnect = false;
|
||||||
|
|
||||||
|
public void doPlayAfterConnect(final boolean playAfterConnection) {
|
||||||
|
this.playAfterConnect = playAfterConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(final ComponentName compName) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Player service is disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
final Context context = getCommonContext();
|
||||||
public void onServiceConnected(final ComponentName compName, final IBinder service) {
|
unbind(context);
|
||||||
if (DEBUG) {
|
}
|
||||||
Log.d(TAG, "Player service is connected");
|
|
||||||
}
|
|
||||||
final MainPlayer.LocalBinder localBinder = (MainPlayer.LocalBinder) service;
|
|
||||||
|
|
||||||
playerService = localBinder.getService();
|
@Override
|
||||||
player = localBinder.getPlayer();
|
public void onServiceConnected(final ComponentName compName, final IBinder service) {
|
||||||
if (listener != null) {
|
if (DEBUG) {
|
||||||
listener.onServiceConnected(player, playerService, playAfterConnect);
|
Log.d(TAG, "Player service is connected");
|
||||||
}
|
|
||||||
startPlayerListener();
|
|
||||||
}
|
}
|
||||||
};
|
final MainPlayer.LocalBinder localBinder = (MainPlayer.LocalBinder) service;
|
||||||
}
|
|
||||||
|
|
||||||
private static void bind(final Context context) {
|
playerService = localBinder.getService();
|
||||||
|
player = localBinder.getPlayer();
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onServiceConnected(player, playerService, playAfterConnect);
|
||||||
|
}
|
||||||
|
startPlayerListener();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void bind(final Context context) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "bind() called");
|
Log.d(TAG, "bind() called");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Intent serviceIntent = new Intent(context, MainPlayer.class);
|
final Intent serviceIntent = new Intent(context, MainPlayer.class);
|
||||||
bound = context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
bound = context.bindService(serviceIntent, serviceConnection,
|
||||||
|
Context.BIND_AUTO_CREATE);
|
||||||
if (!bound) {
|
if (!bound) {
|
||||||
context.unbindService(serviceConnection);
|
context.unbindService(serviceConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static 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");
|
||||||
}
|
}
|
||||||
@ -153,21 +176,19 @@ public final class PlayerHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startPlayerListener() {
|
||||||
private static void startPlayerListener() {
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.setFragmentListener(INNER_LISTENER);
|
player.setFragmentListener(internalListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void stopPlayerListener() {
|
private void stopPlayerListener() {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.removeFragmentListener(INNER_LISTENER);
|
player.removeFragmentListener(internalListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final PlayerServiceEventListener internalListener =
|
||||||
private static final PlayerServiceEventListener INNER_LISTENER =
|
|
||||||
new PlayerServiceEventListener() {
|
new PlayerServiceEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFullscreenStateChanged(final boolean fullscreen) {
|
public void onFullscreenStateChanged(final boolean fullscreen) {
|
||||||
@ -242,7 +263,7 @@ public final class PlayerHolder {
|
|||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onServiceStopped();
|
listener.onServiceStopped();
|
||||||
}
|
}
|
||||||
unbind(App.getApp());
|
unbind(getCommonContext());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -350,13 +350,13 @@ public final class NavigationHelper {
|
|||||||
final boolean switchingPlayers) {
|
final boolean switchingPlayers) {
|
||||||
|
|
||||||
final boolean autoPlay;
|
final boolean autoPlay;
|
||||||
@Nullable final MainPlayer.PlayerType playerType = PlayerHolder.getType();
|
@Nullable final MainPlayer.PlayerType playerType = PlayerHolder.getInstance().getType();
|
||||||
if (playerType == null) {
|
if (playerType == null) {
|
||||||
// no player open
|
// no player open
|
||||||
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
||||||
} else if (switchingPlayers) {
|
} else if (switchingPlayers) {
|
||||||
// switching player to main player
|
// switching player to main player
|
||||||
autoPlay = PlayerHolder.isPlaying(); // keep play/pause state
|
autoPlay = PlayerHolder.getInstance().isPlaying(); // keep play/pause state
|
||||||
} else if (playerType == MainPlayer.PlayerType.VIDEO) {
|
} else if (playerType == MainPlayer.PlayerType.VIDEO) {
|
||||||
// opening new stream while already playing in main player
|
// opening new stream while already playing in main player
|
||||||
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
autoPlay = PlayerHelper.isAutoplayAllowedByUser(context);
|
||||||
|
@ -39,7 +39,7 @@ public enum StreamDialogEntry {
|
|||||||
* Info: Add this entry within showStreamDialog.
|
* Info: Add this entry within showStreamDialog.
|
||||||
*/
|
*/
|
||||||
enqueue(R.string.enqueue_stream, (fragment, item) -> {
|
enqueue(R.string.enqueue_stream, (fragment, item) -> {
|
||||||
final MainPlayer.PlayerType type = PlayerHolder.getType();
|
final MainPlayer.PlayerType type = PlayerHolder.getInstance().getType();
|
||||||
|
|
||||||
if (type == AUDIO) {
|
if (type == AUDIO) {
|
||||||
NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(),
|
NavigationHelper.enqueueOnBackgroundPlayer(fragment.getContext(),
|
||||||
|
Loading…
Reference in New Issue
Block a user