mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-25 12:32:31 +01:00
Completely close player when changing stream w/o autoplay
This commit is contained in:
parent
1d935b46f9
commit
cf9b482be2
@ -201,7 +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();
|
private final PlayerHolder playerHolder = PlayerHolder.getInstance();
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Service management
|
// Service management
|
||||||
@ -762,7 +762,7 @@ public final class VideoDetailFragment
|
|||||||
|
|
||||||
private void setupFromHistoryItem(final StackItem item) {
|
private void setupFromHistoryItem(final StackItem item) {
|
||||||
setAutoPlay(false);
|
setAutoPlay(false);
|
||||||
hideMainPlayer();
|
hideMainPlayerOnLoadingNewStream();
|
||||||
|
|
||||||
setInitialData(item.getServiceId(), item.getUrl(),
|
setInitialData(item.getServiceId(), item.getUrl(),
|
||||||
item.getTitle() == null ? "" : item.getTitle(), item.getPlayQueue());
|
item.getTitle() == null ? "" : item.getTitle(), item.getPlayQueue());
|
||||||
@ -882,7 +882,7 @@ public final class VideoDetailFragment
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(result -> {
|
.subscribe(result -> {
|
||||||
isLoading.set(false);
|
isLoading.set(false);
|
||||||
hideMainPlayer();
|
hideMainPlayerOnLoadingNewStream();
|
||||||
if (result.getAgeLimit() != NO_AGE_LIMIT && !prefs.getBoolean(
|
if (result.getAgeLimit() != NO_AGE_LIMIT && !prefs.getBoolean(
|
||||||
getString(R.string.show_age_restricted_content), false)) {
|
getString(R.string.show_age_restricted_content), false)) {
|
||||||
hideAgeRestrictedContent();
|
hideAgeRestrictedContent();
|
||||||
@ -1174,7 +1174,14 @@ public final class VideoDetailFragment
|
|||||||
ContextCompat.startForegroundService(activity, playerIntent);
|
ContextCompat.startForegroundService(activity, playerIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideMainPlayer() {
|
/**
|
||||||
|
* When the video detail fragment is already showing details for a video and the user opens a
|
||||||
|
* new one, the video detail fragment changes all of its old data to the new stream, so if there
|
||||||
|
* is a video player currently open it should be hidden. This method does exactly that. If
|
||||||
|
* autoplay is enabled, the underlying player is not stopped completely, since it is going to
|
||||||
|
* be reused in a few milliseconds and the flickering would be annoying.
|
||||||
|
*/
|
||||||
|
private void hideMainPlayerOnLoadingNewStream() {
|
||||||
if (!isPlayerServiceAvailable()
|
if (!isPlayerServiceAvailable()
|
||||||
|| playerService.getView() == null
|
|| playerService.getView() == null
|
||||||
|| !player.videoPlayerSelected()) {
|
|| !player.videoPlayerSelected()) {
|
||||||
@ -1182,8 +1189,12 @@ public final class VideoDetailFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeVideoPlayerView();
|
removeVideoPlayerView();
|
||||||
playerService.stop(isAutoplayEnabled());
|
if (isAutoplayEnabled()) {
|
||||||
playerService.getView().setVisibility(View.GONE);
|
playerService.stopForImmediateReusing();
|
||||||
|
playerService.getView().setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
playerHolder.stopService();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayQueue setupPlayQueueForIntent(final boolean append) {
|
private PlayQueue setupPlayQueueForIntent(final boolean append) {
|
||||||
@ -1832,7 +1843,7 @@ public final class VideoDetailFragment
|
|||||||
|| error.type == ExoPlaybackException.TYPE_UNEXPECTED) {
|
|| error.type == ExoPlaybackException.TYPE_UNEXPECTED) {
|
||||||
// Properly exit from fullscreen
|
// Properly exit from fullscreen
|
||||||
toggleFullscreenIfInFullscreenMode();
|
toggleFullscreenIfInFullscreenMode();
|
||||||
hideMainPlayer();
|
hideMainPlayerOnLoadingNewStream();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,32 +133,29 @@ public final class MainPlayer extends Service {
|
|||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(final boolean autoplayEnabled) {
|
public void stopForImmediateReusing() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "stop() called");
|
Log.d(TAG, "stopForImmediateReusing() called");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.exoPlayerIsNull()) {
|
if (!player.exoPlayerIsNull()) {
|
||||||
player.saveWasPlaying();
|
player.saveWasPlaying();
|
||||||
|
|
||||||
// Releases wifi & cpu, disables keepScreenOn, etc.
|
// Releases wifi & cpu, disables keepScreenOn, etc.
|
||||||
if (!autoplayEnabled) {
|
|
||||||
player.pause();
|
|
||||||
}
|
|
||||||
// We can't just pause the player here because it will make transition
|
// We can't just pause the player here because it will make transition
|
||||||
// from one stream to a new stream not smooth
|
// from one stream to a new stream not smooth
|
||||||
player.smoothStopPlayer();
|
player.smoothStopPlayer();
|
||||||
player.setRecovery();
|
player.setRecovery();
|
||||||
|
|
||||||
// Android TV will handle back button in case controls will be visible
|
// Android TV will handle back button in case controls will be visible
|
||||||
// (one more additional unneeded click while the player is hidden)
|
// (one more additional unneeded click while the player is hidden)
|
||||||
player.hideControls(0, 0);
|
player.hideControls(0, 0);
|
||||||
player.closeItemsList();
|
player.closeItemsList();
|
||||||
|
|
||||||
// Notification shows information about old stream but if a user selects
|
// Notification shows information about old stream but if a user selects
|
||||||
// a stream from backStack it's not actual anymore
|
// a stream from backStack it's not actual anymore
|
||||||
// So we should hide the notification at all.
|
// So we should hide the notification at all.
|
||||||
// When autoplay enabled such notification flashing is annoying so skip this case
|
// When autoplay enabled such notification flashing is annoying so skip this case
|
||||||
if (!autoplayEnabled) {
|
|
||||||
NotificationUtil.getInstance().cancelNotificationAndStopForeground(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user