1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-06-26 07:03:20 +00:00

Fixed a situation when background playback could use a video stream instead of an audio stream

This commit is contained in:
Avently 2020-07-22 02:20:58 +03:00
parent 3ecbbea7cb
commit 7aa8a5c368
2 changed files with 30 additions and 16 deletions

View File

@ -2164,10 +2164,10 @@ public class VideoDetailFragment
@Override
public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
bottomSheetState = newState;
ViewGroup mainFragment = requireActivity().findViewById(R.id.fragment_holder);
final ViewGroup mainFragment = requireActivity().findViewById(R.id.fragment_holder);
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
mainFragment.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
bottomSheetBehavior.setPeekHeight(0);
cleanUp();
break;

View File

@ -187,6 +187,7 @@ public class VideoPlayerImpl extends VideoPlayer
private boolean audioOnly = false;
private boolean isFullscreen = false;
private boolean isVerticalVideo = false;
private boolean fragmentIsVisible = false;
boolean shouldUpdateOnProgress;
int timesNotificationUpdated;
@ -1224,28 +1225,22 @@ public class VideoPlayerImpl extends VideoPlayer
break;
case ACTION_PLAY_PAUSE:
onPlayPause();
if (!fragmentIsVisible) {
// Ensure that we have audio-only stream playing when a user
// started to play from notification's play button from outside of the app
onFragmentStopped();
}
break;
case ACTION_REPEAT:
onRepeatClicked();
break;
case VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED:
fragmentIsVisible = true;
useVideoSource(true);
break;
case VideoDetailFragment.ACTION_VIDEO_FRAGMENT_STOPPED:
// This will be called when user goes to another app/activity, turns off a screen.
// We don't want to interrupt playback and don't want to see notification
// if player is stopped.
// Next lines of code will enable background playback if needed
if (videoPlayerSelected() && (isPlaying() || isLoading())) {
if (backgroundPlaybackEnabled()) {
useVideoSource(false);
} else if (minimizeOnPopupEnabled()) {
setRecovery();
NavigationHelper.playOnPopupPlayer(getParentActivity(), playQueue, true);
} else {
onPause();
}
}
fragmentIsVisible = false;
onFragmentStopped();
break;
case Intent.ACTION_CONFIGURATION_CHANGED:
assureCorrectAppLanguage(service);
@ -1998,6 +1993,7 @@ public class VideoPlayerImpl extends VideoPlayer
public void setFragmentListener(final PlayerServiceEventListener listener) {
fragmentListener = listener;
fragmentIsVisible = true;
updateMetadata();
updatePlayback();
triggerProgressUpdate();
@ -2072,6 +2068,24 @@ public class VideoPlayerImpl extends VideoPlayer
}
}
/**
* This will be called when a user goes to another app/activity, turns off a screen.
* We don't want to interrupt playback and don't want to see notification so
* next lines of code will enable audio-only playback only if needed
* */
private void onFragmentStopped() {
if (videoPlayerSelected() && (isPlaying() || isLoading())) {
if (backgroundPlaybackEnabled()) {
useVideoSource(false);
} else if (minimizeOnPopupEnabled()) {
setRecovery();
NavigationHelper.playOnPopupPlayer(getParentActivity(), playQueue, true);
} else {
onPause();
}
}
}
///////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////