mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-15 13:21:22 +01:00
Fixed a situation when background playback could use a video stream instead of an audio stream
This commit is contained in:
parent
3ecbbea7cb
commit
7aa8a5c368
@ -2164,10 +2164,10 @@ public class VideoDetailFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
|
public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
|
||||||
bottomSheetState = newState;
|
bottomSheetState = newState;
|
||||||
ViewGroup mainFragment = requireActivity().findViewById(R.id.fragment_holder);
|
final ViewGroup mainFragment = requireActivity().findViewById(R.id.fragment_holder);
|
||||||
|
|
||||||
switch (newState) {
|
switch (newState) {
|
||||||
case BottomSheetBehavior.STATE_HIDDEN:
|
case BottomSheetBehavior.STATE_HIDDEN:
|
||||||
|
mainFragment.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
|
||||||
bottomSheetBehavior.setPeekHeight(0);
|
bottomSheetBehavior.setPeekHeight(0);
|
||||||
cleanUp();
|
cleanUp();
|
||||||
break;
|
break;
|
||||||
|
@ -187,6 +187,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
private boolean audioOnly = false;
|
private boolean audioOnly = false;
|
||||||
private boolean isFullscreen = false;
|
private boolean isFullscreen = false;
|
||||||
private boolean isVerticalVideo = false;
|
private boolean isVerticalVideo = false;
|
||||||
|
private boolean fragmentIsVisible = false;
|
||||||
boolean shouldUpdateOnProgress;
|
boolean shouldUpdateOnProgress;
|
||||||
int timesNotificationUpdated;
|
int timesNotificationUpdated;
|
||||||
|
|
||||||
@ -1224,28 +1225,22 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
break;
|
break;
|
||||||
case ACTION_PLAY_PAUSE:
|
case ACTION_PLAY_PAUSE:
|
||||||
onPlayPause();
|
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;
|
break;
|
||||||
case ACTION_REPEAT:
|
case ACTION_REPEAT:
|
||||||
onRepeatClicked();
|
onRepeatClicked();
|
||||||
break;
|
break;
|
||||||
case VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED:
|
case VideoDetailFragment.ACTION_VIDEO_FRAGMENT_RESUMED:
|
||||||
|
fragmentIsVisible = true;
|
||||||
useVideoSource(true);
|
useVideoSource(true);
|
||||||
break;
|
break;
|
||||||
case VideoDetailFragment.ACTION_VIDEO_FRAGMENT_STOPPED:
|
case VideoDetailFragment.ACTION_VIDEO_FRAGMENT_STOPPED:
|
||||||
// This will be called when user goes to another app/activity, turns off a screen.
|
fragmentIsVisible = false;
|
||||||
// We don't want to interrupt playback and don't want to see notification
|
onFragmentStopped();
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_CONFIGURATION_CHANGED:
|
case Intent.ACTION_CONFIGURATION_CHANGED:
|
||||||
assureCorrectAppLanguage(service);
|
assureCorrectAppLanguage(service);
|
||||||
@ -1998,6 +1993,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
|
|
||||||
public void setFragmentListener(final PlayerServiceEventListener listener) {
|
public void setFragmentListener(final PlayerServiceEventListener listener) {
|
||||||
fragmentListener = listener;
|
fragmentListener = listener;
|
||||||
|
fragmentIsVisible = true;
|
||||||
updateMetadata();
|
updateMetadata();
|
||||||
updatePlayback();
|
updatePlayback();
|
||||||
triggerProgressUpdate();
|
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
|
// Getters
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user