mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Refactoring and made the player returning from landscape & fullscreen on vertical video to portrait after clicking on fullscreen button
This commit is contained in:
parent
d0fc9fda71
commit
9a0c2c40bd
@ -112,6 +112,7 @@ import static org.schabi.newpipe.player.MainPlayer.ACTION_REPEAT;
|
|||||||
import static org.schabi.newpipe.player.MainPlayer.NOTIFICATION_ID;
|
import static org.schabi.newpipe.player.MainPlayer.NOTIFICATION_ID;
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
|
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
|
||||||
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
import static org.schabi.newpipe.player.helper.PlayerHelper.getTimeString;
|
||||||
|
import static org.schabi.newpipe.player.helper.PlayerHelper.globalScreenOrientationLocked;
|
||||||
import static org.schabi.newpipe.util.AnimationUtils.Type.SLIDE_AND_ALPHA;
|
import static org.schabi.newpipe.util.AnimationUtils.Type.SLIDE_AND_ALPHA;
|
||||||
import static org.schabi.newpipe.util.AnimationUtils.animateRotation;
|
import static org.schabi.newpipe.util.AnimationUtils.animateRotation;
|
||||||
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
import static org.schabi.newpipe.util.AnimationUtils.animateView;
|
||||||
@ -708,62 +709,33 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Player Overrides
|
// Player Overrides
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toggleFullscreen() {
|
public void toggleFullscreen() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "toggleFullscreen() called");
|
Log.d(TAG, "toggleFullscreen() called");
|
||||||
}
|
}
|
||||||
if (simpleExoPlayer == null || getCurrentMetadata() == null) {
|
if (popupPlayerSelected()
|
||||||
|
|| simpleExoPlayer == null
|
||||||
|
|| getCurrentMetadata() == null
|
||||||
|
|| fragmentListener == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (popupPlayerSelected()) {
|
isFullscreen = !isFullscreen;
|
||||||
setRecovery();
|
if (!isFullscreen) {
|
||||||
service.removeViewFromParent();
|
// Apply window insets because Android will not do it when orientation changes
|
||||||
final Intent intent = NavigationHelper.getPlayerIntent(
|
// from landscape to portrait (open vertical video to reproduce)
|
||||||
service,
|
getControlsRoot().setPadding(0, 0, 0, 0);
|
||||||
MainActivity.class,
|
|
||||||
this.getPlayQueue(),
|
|
||||||
this.getRepeatMode(),
|
|
||||||
this.getPlaybackSpeed(),
|
|
||||||
this.getPlaybackPitch(),
|
|
||||||
this.getPlaybackSkipSilence(),
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
!isPlaying(),
|
|
||||||
isMuted()
|
|
||||||
);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
intent.putExtra(Constants.KEY_SERVICE_ID,
|
|
||||||
getCurrentMetadata().getMetadata().getServiceId());
|
|
||||||
intent.putExtra(Constants.KEY_LINK_TYPE, StreamingService.LinkType.STREAM);
|
|
||||||
intent.putExtra(Constants.KEY_URL, getVideoUrl());
|
|
||||||
intent.putExtra(Constants.KEY_TITLE, getVideoTitle());
|
|
||||||
intent.putExtra(VideoDetailFragment.AUTO_PLAY, true);
|
|
||||||
service.onDestroy();
|
|
||||||
context.startActivity(intent);
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
if (fragmentListener == null) {
|
// Android needs tens milliseconds to send new insets but a user is able to see
|
||||||
return;
|
// how controls changes it's position from `0` to `nav bar height` padding.
|
||||||
}
|
// So just hide the controls to hide this visual inconsistency
|
||||||
|
hideControls(0, 0);
|
||||||
isFullscreen = !isFullscreen;
|
|
||||||
if (!isFullscreen) {
|
|
||||||
// Apply window insets because Android will not do it when orientation changes
|
|
||||||
// from landscape to portrait (open vertical video to reproduce)
|
|
||||||
getControlsRoot().setPadding(0, 0, 0, 0);
|
|
||||||
} else {
|
|
||||||
// Android needs tens milliseconds to send new insets but a user is able to see
|
|
||||||
// how controls changes it's position from `0` to `nav bar height` padding.
|
|
||||||
// So just hide the controls to hide this visual inconsistency
|
|
||||||
hideControls(0, 0);
|
|
||||||
}
|
|
||||||
fragmentListener.onFullscreenStateChanged(isFullscreen());
|
|
||||||
}
|
}
|
||||||
|
fragmentListener.onFullscreenStateChanged(isFullscreen());
|
||||||
|
|
||||||
if (!isFullscreen()) {
|
if (!isFullscreen()) {
|
||||||
titleTextView.setVisibility(View.GONE);
|
titleTextView.setVisibility(View.GONE);
|
||||||
@ -777,6 +749,40 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
setupScreenRotationButton();
|
setupScreenRotationButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void switchFromPopupToMain() {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "switchFromPopupToMain() called");
|
||||||
|
}
|
||||||
|
if (!popupPlayerSelected() || simpleExoPlayer == null || getCurrentMetadata() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRecovery();
|
||||||
|
service.removeViewFromParent();
|
||||||
|
final Intent intent = NavigationHelper.getPlayerIntent(
|
||||||
|
service,
|
||||||
|
MainActivity.class,
|
||||||
|
this.getPlayQueue(),
|
||||||
|
this.getRepeatMode(),
|
||||||
|
this.getPlaybackSpeed(),
|
||||||
|
this.getPlaybackPitch(),
|
||||||
|
this.getPlaybackSkipSilence(),
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
!isPlaying(),
|
||||||
|
isMuted()
|
||||||
|
);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.putExtra(Constants.KEY_SERVICE_ID,
|
||||||
|
getCurrentMetadata().getMetadata().getServiceId());
|
||||||
|
intent.putExtra(Constants.KEY_LINK_TYPE, StreamingService.LinkType.STREAM);
|
||||||
|
intent.putExtra(Constants.KEY_URL, getVideoUrl());
|
||||||
|
intent.putExtra(Constants.KEY_TITLE, getVideoTitle());
|
||||||
|
intent.putExtra(VideoDetailFragment.AUTO_PLAY, true);
|
||||||
|
service.onDestroy();
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
super.onClick(v);
|
super.onClick(v);
|
||||||
@ -804,9 +810,12 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||||||
} else if (v.getId() == openInBrowser.getId()) {
|
} else if (v.getId() == openInBrowser.getId()) {
|
||||||
onOpenInBrowserClicked();
|
onOpenInBrowserClicked();
|
||||||
} else if (v.getId() == fullscreenButton.getId()) {
|
} else if (v.getId() == fullscreenButton.getId()) {
|
||||||
toggleFullscreen();
|
switchFromPopupToMain();
|
||||||
} else if (v.getId() == screenRotationButton.getId()) {
|
} else if (v.getId() == screenRotationButton.getId()) {
|
||||||
if (!isVerticalVideo) {
|
// Only if it's not a vertical video or vertical video but in landscape with locked
|
||||||
|
// orientation a screen orientation can be changed automatically
|
||||||
|
if (!isVerticalVideo
|
||||||
|
|| (service.isLandscape() && globalScreenOrientationLocked(service))) {
|
||||||
fragmentListener.onScreenRotationButtonClicked();
|
fragmentListener.onScreenRotationButtonClicked();
|
||||||
} else {
|
} else {
|
||||||
toggleFullscreen();
|
toggleFullscreen();
|
||||||
|
Loading…
Reference in New Issue
Block a user