Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ public final class VideoDetailFragment
};

@State
protected int serviceId = Constants.NO_SERVICE_ID;
int serviceId = Constants.NO_SERVICE_ID;
@State
@NonNull
protected String title = "";
String title = "";
@State
@Nullable
protected String url = null;
String url = null;
@Nullable
protected PlayQueue playQueue = null;
private PlayQueue playQueue = null;
@State
int bottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
@State
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
@State
protected boolean autoPlayEnabled = true;
boolean autoPlayEnabled = true;

@Nullable
private StreamInfo currentInfo = null;
Expand Down Expand Up @@ -438,18 +438,15 @@ public void onDestroyView() {
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case ReCaptchaActivity.RECAPTCHA_REQUEST:
if (resultCode == Activity.RESULT_OK) {
NavigationHelper.openVideoDetailFragment(requireContext(), getFM(),
serviceId, url, title, null, false);
} else {
Log.e(TAG, "ReCaptcha failed");
}
break;
default:
Log.e(TAG, "Request code from activity not supported [" + requestCode + "]");
break;
if (requestCode == ReCaptchaActivity.RECAPTCHA_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
NavigationHelper.openVideoDetailFragment(requireContext(), getFM(),
serviceId, url, title, null, false);
} else {
Log.e(TAG, "ReCaptcha failed");
}
} else {
Log.e(TAG, "Request code from activity not supported [" + requestCode + "]");
}
}

Expand Down Expand Up @@ -815,25 +812,17 @@ private void prepareAndHandleInfo(final StreamInfo info, final boolean scrollToT

}

protected void prepareAndLoadInfo() {
private void prepareAndLoadInfo() {
scrollToTop();
startLoading(false);
}

@Override
public void startLoading(final boolean forceLoad) {
super.startLoading(forceLoad);

initTabs();
currentInfo = null;
if (currentWorker != null) {
currentWorker.dispose();
}

runWorker(forceLoad, stack.isEmpty());
startLoading(forceLoad, null);
}

private void startLoading(final boolean forceLoad, final boolean addToBackStack) {
private void startLoading(final boolean forceLoad, final @Nullable Boolean addToBackStack) {
super.startLoading(forceLoad);

initTabs();
Expand All @@ -842,7 +831,7 @@ private void startLoading(final boolean forceLoad, final boolean addToBackStack)
currentWorker.dispose();
}

runWorker(forceLoad, addToBackStack);
runWorker(forceLoad, addToBackStack != null ? addToBackStack : stack.isEmpty());
}

private void runWorker(final boolean forceLoad, final boolean addToBackStack) {
Expand Down Expand Up @@ -1138,7 +1127,7 @@ private void openNormalBackgroundPlayer(final boolean append) {
}

private void openMainPlayer() {
if (!isPlayerServiceAvailable()) {
if (noPlayerServiceAvailable()) {
playerHolder.startService(autoPlayEnabled, this);
return;
}
Expand All @@ -1163,7 +1152,7 @@ private void openMainPlayer() {
*/
private void hideMainPlayerOnLoadingNewStream() {
final var root = getRoot();
if (!isPlayerServiceAvailable() || root.isEmpty() || !player.videoPlayerSelected()) {
if (noPlayerServiceAvailable() || root.isEmpty() || !player.videoPlayerSelected()) {
return;
}

Expand Down Expand Up @@ -1337,31 +1326,31 @@ private void showContent() {
binding.detailContentRootHiding.setVisibility(View.VISIBLE);
}

protected void setInitialData(final int newServiceId,
@Nullable final String newUrl,
@NonNull final String newTitle,
@Nullable final PlayQueue newPlayQueue) {
private void setInitialData(final int newServiceId,
@Nullable final String newUrl,
@NonNull final String newTitle,
@Nullable final PlayQueue newPlayQueue) {
this.serviceId = newServiceId;
this.url = newUrl;
this.title = newTitle;
this.playQueue = newPlayQueue;
}

private void setErrorImage(final int imageResource) {
private void setErrorImage() {
if (binding == null || activity == null) {
return;
}

binding.detailThumbnailImageView.setImageDrawable(
AppCompatResources.getDrawable(requireContext(), imageResource));
AppCompatResources.getDrawable(requireContext(), R.drawable.not_available_monkey));
animate(binding.detailThumbnailImageView, false, 0, AnimationType.ALPHA,
0, () -> animate(binding.detailThumbnailImageView, true, 500));
}

@Override
public void handleError() {
super.handleError();
setErrorImage(R.drawable.not_available_monkey);
setErrorImage();

if (binding.relatedItemsLayout != null) { // hide related streams for tablets
binding.relatedItemsLayout.setVisibility(View.INVISIBLE);
Expand Down Expand Up @@ -1776,16 +1765,14 @@ public void onPlaybackUpdate(final int state,
final PlaybackParameters parameters) {
setOverlayPlayPauseImage(player != null && player.isPlaying());

switch (state) {
case Player.STATE_PLAYING:
if (binding.positionView.getAlpha() != 1.0f
&& player.getPlayQueue() != null
&& player.getPlayQueue().getItem() != null
&& player.getPlayQueue().getItem().getUrl().equals(url)) {
animate(binding.positionView, true, 100);
animate(binding.detailPositionView, true, 100);
}
break;
if (state == Player.STATE_PLAYING) {
if (binding.positionView.getAlpha() != 1.0f
&& player.getPlayQueue() != null
&& player.getPlayQueue().getItem() != null
&& player.getPlayQueue().getItem().getUrl().equals(url)) {
animate(binding.positionView, true, 100);
animate(binding.detailPositionView, true, 100);
}
}
}

Expand Down Expand Up @@ -2444,8 +2431,8 @@ boolean isPlayerAvailable() {
return player != null;
}

boolean isPlayerServiceAvailable() {
return playerService != null;
boolean noPlayerServiceAvailable() {
return playerService == null;
}

boolean isPlayerAndPlayerServiceAvailable() {
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,18 @@ public void onServiceDisconnected(final ComponentName name) {
}

@Override
public void onServiceConnected(final ComponentName name, final IBinder service) {
public void onServiceConnected(final ComponentName name, final IBinder binder) {
Log.d(TAG, "Player service is connected");

if (service instanceof PlayerService.LocalBinder) {
player = ((PlayerService.LocalBinder) service).getService().getPlayer();
if (binder instanceof PlayerService.LocalBinder) {
@Nullable final PlayerService s =
((PlayerService.LocalBinder) binder).getService();
if (s == null) {
throw new IllegalArgumentException(
"PlayerService.LocalBinder.getService() must never be"
+ "null after the service connects");
}
player = s.getPlayer();
}

if (player == null || player.getPlayQueue() == null || player.exoPlayerIsNull()) {
Expand Down
26 changes: 20 additions & 6 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,15 @@ private void initUIsForCurrentPlayerType() {

switch (playerType) {
case MAIN:
UIs.destroyAll(PopupPlayerUi.class);
UIs.destroyAllOfType(PopupPlayerUi.class);
UIs.addAndPrepare(new MainPlayerUi(this, binding));
break;
case POPUP:
UIs.destroyAll(MainPlayerUi.class);
UIs.destroyAllOfType(MainPlayerUi.class);
UIs.addAndPrepare(new PopupPlayerUi(this, binding));
break;
case AUDIO:
UIs.destroyAll(VideoPlayerUi.class);
UIs.destroyAllOfType(VideoPlayerUi.class);
break;
}
}
Expand Down Expand Up @@ -591,9 +591,15 @@ private void destroyPlayer() {
}
}

public void destroy() {

/**
* Shut down this player.
* Saves the stream progress, sets recovery.
* Then destroys the player in all UIs and destroys the UIs as well.
*/
public void saveAndShutdown() {
if (DEBUG) {
Log.d(TAG, "destroy() called");
Log.d(TAG, "saveAndShutdown() called");
}

saveStreamProgressState();
Expand All @@ -606,7 +612,7 @@ public void destroy() {
databaseUpdateDisposable.clear();
progressUpdateDisposable.set(null);

UIs.destroyAll(Object.class); // destroy every UI: obviously every UI extends Object
UIs.destroyAllOfType(null);
}

public void setRecovery() {
Expand Down Expand Up @@ -1995,6 +2001,10 @@ public void setFragmentListener(final PlayerServiceEventListener listener) {
triggerProgressUpdate();
}

/**
* Remove the listener, if it was set.
* @param listener listener to remove
* */
Comment thread
Profpatsch marked this conversation as resolved.
public void removeFragmentListener(final PlayerServiceEventListener listener) {
if (fragmentListener == listener) {
fragmentListener = null;
Expand All @@ -2009,6 +2019,10 @@ void setActivityListener(final PlayerEventListener listener) {
triggerProgressUpdate();
}

/**
* Remove the listener, if it was set.
* @param listener listener to remove
* */
void removeActivityListener(final PlayerEventListener listener) {
if (activityListener == listener) {
activityListener = null;
Expand Down
Loading