diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java
index e72d4609e..9bcbe4ff1 100644
--- a/app/src/main/java/org/schabi/newpipe/MainActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java
@@ -30,9 +30,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
-import androidx.preference.PreferenceManager;
import android.util.Log;
-
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -46,6 +44,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
+
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
@@ -55,6 +54,7 @@ import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
+import androidx.preference.PreferenceManager;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.navigation.NavigationView;
@@ -69,10 +69,11 @@ import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.fragments.list.search.SearchFragment;
import org.schabi.newpipe.player.VideoPlayer;
import org.schabi.newpipe.player.event.OnKeyDownListener;
+import org.schabi.newpipe.player.helper.PlayerHolder;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
-import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.Constants;
+import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
@@ -87,6 +88,7 @@ import org.schabi.newpipe.views.FocusOverlayView;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
@@ -152,7 +154,7 @@ public class MainActivity extends AppCompatActivity {
if (DeviceUtils.isTv(this)) {
FocusOverlayView.setupFocusObserver(this);
}
- setupBroadcastReceiver();
+ openMiniPlayerUponPlayerStarted();
}
private void setupDrawer() throws Exception {
@@ -758,32 +760,36 @@ public class MainActivity extends AppCompatActivity {
if (intent.hasExtra(Constants.KEY_LINK_TYPE)) {
final String url = intent.getStringExtra(Constants.KEY_URL);
final int serviceId = intent.getIntExtra(Constants.KEY_SERVICE_ID, 0);
- final String title = intent.getStringExtra(Constants.KEY_TITLE);
- switch (((StreamingService.LinkType) intent
- .getSerializableExtra(Constants.KEY_LINK_TYPE))) {
+ String title = intent.getStringExtra(Constants.KEY_TITLE);
+ if (title == null) {
+ title = "";
+ }
+
+ final StreamingService.LinkType linkType = ((StreamingService.LinkType) intent
+ .getSerializableExtra(Constants.KEY_LINK_TYPE));
+ assert linkType != null;
+ switch (linkType) {
case STREAM:
- final boolean autoPlay = intent
- .getBooleanExtra(VideoDetailFragment.AUTO_PLAY, false);
- final String intentCacheKey = intent
- .getStringExtra(VideoPlayer.PLAY_QUEUE_KEY);
+ final String intentCacheKey = intent.getStringExtra(
+ VideoPlayer.PLAY_QUEUE_KEY);
final PlayQueue playQueue = intentCacheKey != null
? SerializedCache.getInstance()
.take(intentCacheKey, PlayQueue.class)
: null;
- NavigationHelper.openVideoDetailFragment(getSupportFragmentManager(),
- serviceId, url, title, autoPlay, playQueue);
+
+ final boolean switchingPlayers = intent.getBooleanExtra(
+ VideoDetailFragment.KEY_SWITCHING_PLAYERS, false);
+ NavigationHelper.openVideoDetailFragment(
+ getApplicationContext(), getSupportFragmentManager(),
+ serviceId, url, title, playQueue, switchingPlayers);
break;
case CHANNEL:
NavigationHelper.openChannelFragment(getSupportFragmentManager(),
- serviceId,
- url,
- title);
+ serviceId, url, title);
break;
case PLAYLIST:
NavigationHelper.openPlaylistFragment(getSupportFragmentManager(),
- serviceId,
- url,
- title);
+ serviceId, url, title);
break;
}
} else if (intent.hasExtra(Constants.KEY_OPEN_SEARCH)) {
@@ -805,34 +811,47 @@ public class MainActivity extends AppCompatActivity {
}
}
- private void setupBroadcastReceiver() {
- broadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(final Context context, final Intent intent) {
- if (intent.getAction().equals(VideoDetailFragment.ACTION_PLAYER_STARTED)) {
- final Fragment fragmentPlayer = getSupportFragmentManager()
- .findFragmentById(R.id.fragment_player_holder);
- if (fragmentPlayer == null) {
- /*
- * We still don't have a fragment attached to the activity.
- * It can happen when a user started popup or background players
- * without opening a stream inside the fragment.
- * Adding it in a collapsed state (only mini player will be visible)
- * */
- NavigationHelper.showMiniPlayer(getSupportFragmentManager());
+ private void openMiniPlayerIfMissing() {
+ final Fragment fragmentPlayer = getSupportFragmentManager()
+ .findFragmentById(R.id.fragment_player_holder);
+ if (fragmentPlayer == null) {
+ // We still don't have a fragment attached to the activity. It can happen when a user
+ // started popup or background players without opening a stream inside the fragment.
+ // Adding it in a collapsed state (only mini player will be visible).
+ NavigationHelper.showMiniPlayer(getSupportFragmentManager());
+ }
+ }
+
+ private void openMiniPlayerUponPlayerStarted() {
+ if (getIntent().getSerializableExtra(Constants.KEY_LINK_TYPE)
+ == StreamingService.LinkType.STREAM) {
+ // handleIntent() already takes care of opening video detail fragment
+ // due to an intent containing a STREAM link
+ return;
+ }
+
+ if (PlayerHolder.isPlayerOpen()) {
+ // if the player is already open, no need for a broadcast receiver
+ openMiniPlayerIfMissing();
+ } else {
+ // listen for player start intent being sent around
+ broadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(final Context context, final Intent intent) {
+ if (Objects.equals(intent.getAction(),
+ VideoDetailFragment.ACTION_PLAYER_STARTED)) {
+ openMiniPlayerIfMissing();
+ // At this point the player is added 100%, we can unregister. Other actions
+ // are useless since the fragment will not be removed after that.
+ unregisterReceiver(broadcastReceiver);
+ broadcastReceiver = null;
}
- /*
- * At this point the player is added 100%, we can unregister.
- * Other actions are useless since the fragment will not be removed after that
- * */
- unregisterReceiver(broadcastReceiver);
- broadcastReceiver = null;
}
- }
- };
- final IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(VideoDetailFragment.ACTION_PLAYER_STARTED);
- registerReceiver(broadcastReceiver, intentFilter);
+ };
+ final IntentFilter intentFilter = new IntentFilter();
+ intentFilter.addAction(VideoDetailFragment.ACTION_PLAYER_STARTED);
+ registerReceiver(broadcastReceiver, intentFilter);
+ }
}
private boolean bottomSheetHiddenOrCollapsed() {
diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java
index 388d7683a..537d71901 100644
--- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java
@@ -40,7 +40,9 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream;
+import org.schabi.newpipe.player.MainPlayer;
import org.schabi.newpipe.player.helper.PlayerHelper;
+import org.schabi.newpipe.player.helper.PlayerHolder;
import org.schabi.newpipe.player.playqueue.ChannelPlayQueue;
import org.schabi.newpipe.player.playqueue.PlayQueue;
import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue;
@@ -60,8 +62,6 @@ import org.schabi.newpipe.views.FocusOverlayView;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import icepick.Icepick;
@@ -116,8 +116,6 @@ public class RouterActivity extends AppCompatActivity {
}
}
- internalRoute = getIntent().getBooleanExtra(INTERNAL_ROUTE_KEY, false);
-
setTheme(ThemeHelper.isLightThemeSelected(this)
? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark);
}
@@ -398,14 +396,22 @@ public class RouterActivity extends AppCompatActivity {
// show both "show info" and "video player", they are two different activities
returnList.add(showInfo);
returnList.add(videoPlayer);
- } else if (capabilities.contains(VIDEO)
- && PlayerHelper.isAutoplayAllowedByUser(context)) {
- // show only "video player" since the details activity will be opened and the video
- // will be autoplayed there and "show info" would do the exact same thing
- returnList.add(videoPlayer);
} else {
- // show only "show info" if video player is not applicable or autoplay is disabled
- returnList.add(showInfo);
+ final MainPlayer.PlayerType playerType = PlayerHolder.getType();
+ if (capabilities.contains(VIDEO)
+ && PlayerHelper.isAutoplayAllowedByUser(context)
+ && playerType == null || playerType == MainPlayer.PlayerType.VIDEO) {
+ // show only "video player" since the details activity will be opened and the
+ // video will be auto played there. Since "show info" would do the exact same
+ // thing, use that as a key to let VideoDetailFragment load the stream instead
+ // of using FetcherService (see comment in handleChoice())
+ returnList.add(new AdapterChoiceItem(
+ showInfo.key, videoPlayer.description, videoPlayer.icon));
+ } else {
+ // show only "show info" if video player is not applicable, auto play is
+ // disabled or a video is playing in a player different than the main one
+ returnList.add(showInfo);
+ }
}
if (capabilities.contains(VIDEO)) {
@@ -492,12 +498,7 @@ public class RouterActivity extends AppCompatActivity {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(intent -> {
- if (!internalRoute) {
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- }
startActivity(intent);
-
finish();
}, throwable -> handleError(throwable, currentUrl))
);
@@ -515,7 +516,7 @@ public class RouterActivity extends AppCompatActivity {
@SuppressLint("CheckResult")
private void openDownloadDialog() {
- ExtractorHelper.getStreamInfo(currentServiceId, currentUrl, true)
+ disposables.add(ExtractorHelper.getStreamInfo(currentServiceId, currentUrl, true)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@NonNull StreamInfo result) -> {
@@ -532,10 +533,10 @@ public class RouterActivity extends AppCompatActivity {
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
downloadDialog.show(fm, "downloadDialog");
fm.executePendingTransactions();
- downloadDialog.getDialog().setOnDismissListener(dialog -> finish());
+ downloadDialog.requireDialog().setOnDismissListener(dialog -> finish());
}, (@NonNull Throwable throwable) -> {
showUnsupportedUrlDialog(currentUrl);
- });
+ }));
}
@Override
@@ -553,66 +554,6 @@ public class RouterActivity extends AppCompatActivity {
}
}
- /*//////////////////////////////////////////////////////////////////////////
- // Service Fetcher
- //////////////////////////////////////////////////////////////////////////*/
-
- private String removeHeadingGibberish(final String input) {
- int start = 0;
- for (int i = input.indexOf("://") - 1; i >= 0; i--) {
- if (!input.substring(i, i + 1).matches("\\p{L}")) {
- start = i + 1;
- break;
- }
- }
- return input.substring(start);
- }
-
- /*//////////////////////////////////////////////////////////////////////////
- // Utils
- //////////////////////////////////////////////////////////////////////////*/
-
- private String trim(final String input) {
- if (input == null || input.length() < 1) {
- return input;
- } else {
- String output = input;
- while (output.length() > 0 && output.substring(0, 1).matches(REGEX_REMOVE_FROM_URL)) {
- output = output.substring(1);
- }
- while (output.length() > 0
- && output.substring(output.length() - 1).matches(REGEX_REMOVE_FROM_URL)) {
- output = output.substring(0, output.length() - 1);
- }
- return output;
- }
- }
-
- /**
- * Retrieves all Strings which look remotely like URLs from a text.
- * Used if NewPipe was called through share menu.
- *
- * @param sharedText text to scan for URLs.
- * @return potential URLs
- */
- protected String[] getUris(final String sharedText) {
- final Collection
- NavigationHelper.playOnMainPlayer(activity, getPlayQueue(), true));
+ NavigationHelper.playOnMainPlayer(activity, getPlayQueue()));
headerPopupButton.setOnClickListener(view ->
NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(), false));
headerBackgroundButton.setOnClickListener(view ->
diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java
index 0e5222f5e..2fc710fb0 100644
--- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayerActivity.java
@@ -2,11 +2,8 @@ package org.schabi.newpipe.player;
import android.content.Intent;
import android.view.Menu;
-import android.view.MenuItem;
import org.schabi.newpipe.R;
-import org.schabi.newpipe.util.NavigationHelper;
-import org.schabi.newpipe.util.PermissionHelper;
public final class BackgroundPlayerActivity extends ServicePlayerActivity {
@@ -46,31 +43,6 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity {
return R.menu.menu_play_queue_bg;
}
- @Override
- public boolean onPlayerOptionSelected(final MenuItem item) {
- if (item.getItemId() == R.id.action_switch_popup) {
-
- if (!PermissionHelper.isPopupEnabled(this)) {
- PermissionHelper.showPopupEnablementToast(this);
- return true;
- }
-
- this.player.setRecovery();
- NavigationHelper.playOnPopupPlayer(
- getApplicationContext(), player.playQueue, this.player.isPlaying());
- return true;
- }
-
- if (item.getItemId() == R.id.action_switch_background) {
- this.player.setRecovery();
- NavigationHelper.playOnBackgroundPlayer(
- getApplicationContext(), player.playQueue, this.player.isPlaying());
- return true;
- }
-
- return false;
- }
-
@Override
public void setupMenu(final Menu menu) {
if (player == null) {
diff --git a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
index 70f2e158b..1355f4285 100644
--- a/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
+++ b/app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
@@ -125,7 +125,7 @@ public abstract class BasePlayer implements
@NonNull
public static final String RESUME_PLAYBACK = "resume_playback";
@NonNull
- public static final String START_PAUSED = "start_paused";
+ public static final String PLAY_WHEN_READY = "play_when_ready";
@NonNull
public static final String SELECT_ON_APPEND = "select_on_append";
@NonNull
@@ -224,7 +224,7 @@ public abstract class BasePlayer implements
this.dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
final TrackSelection.Factory trackSelectionFactory = PlayerHelper
- .getQualitySelector(context);
+ .getQualitySelector();
this.trackSelector = new CustomTrackSelector(context, trackSelectionFactory);
this.loadControl = new LoadController();
@@ -302,6 +302,7 @@ public abstract class BasePlayer implements
final boolean samePlayQueue = playQueue != null && playQueue.equals(queue);
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
+ final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true);
final boolean isMuted = intent
.getBooleanExtra(IS_MUTED, simpleExoPlayer != null && isMuted());
@@ -327,16 +328,20 @@ public abstract class BasePlayer implements
simpleExoPlayer.retry();
}
simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition());
- return;
+ simpleExoPlayer.setPlayWhenReady(playWhenReady);
- } else if (samePlayQueue && !playQueue.isDisposed() && simpleExoPlayer != null) {
+ } else if (simpleExoPlayer != null
+ && samePlayQueue
+ && playQueue != null
+ && !playQueue.isDisposed()) {
// Do not re-init the same PlayQueue. Save time
// Player can have state = IDLE when playback is stopped or failed
// and we should retry() in this case
if (simpleExoPlayer.getPlaybackState() == Player.STATE_IDLE) {
simpleExoPlayer.retry();
}
- return;
+ simpleExoPlayer.setPlayWhenReady(playWhenReady);
+
} else if (intent.getBooleanExtra(RESUME_PLAYBACK, false)
&& isPlaybackResumeEnabled()
&& !samePlayQueue) {
@@ -351,7 +356,7 @@ public abstract class BasePlayer implements
state -> {
queue.setRecovery(queue.getIndex(), state.getProgressTime());
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch,
- playbackSkipSilence, true, isMuted);
+ playbackSkipSilence, playWhenReady, isMuted);
},
error -> {
if (DEBUG) {
@@ -359,24 +364,22 @@ public abstract class BasePlayer implements
}
// In case any error we can start playback without history
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch,
- playbackSkipSilence, true, isMuted);
+ playbackSkipSilence, playWhenReady, isMuted);
},
() -> {
// Completed but not found in history
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch,
- playbackSkipSilence, true, isMuted);
+ playbackSkipSilence, playWhenReady, isMuted);
}
);
databaseUpdateReactor.add(stateLoader);
- return;
}
+ } else {
+ // Good to go...
+ // In a case of equal PlayQueues we can re-init old one but only when it is disposed
+ initPlayback(samePlayQueue ? playQueue : queue, repeatMode, playbackSpeed,
+ playbackPitch, playbackSkipSilence, playWhenReady, isMuted);
}
- // Good to go...
- // In a case of equal PlayQueues we can re-init old one but only when it is disposed
- initPlayback(samePlayQueue ? playQueue : queue, repeatMode,
- playbackSpeed, playbackPitch, playbackSkipSilence,
- !intent.getBooleanExtra(START_PAUSED, false),
- isMuted);
}
private PlaybackParameters retrievePlaybackParametersFromPreferences() {
diff --git a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java
index ea205bbdf..63f6a400e 100644
--- a/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java
+++ b/app/src/main/java/org/schabi/newpipe/player/MainPlayer.java
@@ -30,6 +30,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
+import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import org.schabi.newpipe.R;
@@ -231,6 +232,7 @@ public final class MainPlayer extends Service {
return metrics.heightPixels < metrics.widthPixels;
}
+ @Nullable
public View getView() {
if (playerImpl == null) {
return null;
@@ -240,7 +242,7 @@ public final class MainPlayer extends Service {
}
public void removeViewFromParent() {
- if (getView().getParent() != null) {
+ if (getView() != null && getView().getParent() != null) {
if (playerImpl.getParentActivity() != null) {
// This means view was added to fragment
final ViewGroup parent = (ViewGroup) getView().getParent();
diff --git a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java
index 8b606260a..ad4c603cd 100644
--- a/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/player/ServicePlayerActivity.java
@@ -27,9 +27,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
-import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
-import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
@@ -42,9 +40,9 @@ import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import org.schabi.newpipe.player.playqueue.PlayQueueItemBuilder;
import org.schabi.newpipe.player.playqueue.PlayQueueItemHolder;
import org.schabi.newpipe.player.playqueue.PlayQueueItemTouchCallback;
-import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
+import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ThemeHelper;
import java.util.Collections;
@@ -113,9 +111,8 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
public abstract int getPlayerOptionMenuResource();
- public abstract boolean onPlayerOptionSelected(MenuItem item);
-
public abstract void setupMenu(Menu m);
+
////////////////////////////////////////////////////////////////////////////
// Activity Lifecycle
////////////////////////////////////////////////////////////////////////////
@@ -187,12 +184,22 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
return true;
case R.id.action_switch_main:
this.player.setRecovery();
- getApplicationContext().startActivity(
- getSwitchIntent(MainActivity.class, MainPlayer.PlayerType.VIDEO)
- .putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying()));
+ NavigationHelper.playOnMainPlayer(this, player.getPlayQueue(), true);
+ return true;
+ case R.id.action_switch_popup:
+ if (PermissionHelper.isPopupEnabled(this)) {
+ this.player.setRecovery();
+ NavigationHelper.playOnPopupPlayer(this, player.playQueue, true);
+ } else {
+ PermissionHelper.showPopupEnablementToast(this);
+ }
+ return true;
+ case R.id.action_switch_background:
+ this.player.setRecovery();
+ NavigationHelper.playOnBackgroundPlayer(this, player.playQueue, true);
return true;
}
- return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item);
+ return super.onOptionsItemSelected(item);
}
@Override
@@ -201,24 +208,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
unbind();
}
- protected Intent getSwitchIntent(final Class clazz, final MainPlayer.PlayerType playerType) {
- return NavigationHelper.getPlayerIntent(getApplicationContext(), clazz,
- this.player.getPlayQueue(), this.player.getRepeatMode(),
- this.player.getPlaybackSpeed(), this.player.getPlaybackPitch(),
- this.player.getPlaybackSkipSilence(),
- null,
- true,
- !this.player.isPlaying(),
- this.player.isMuted())
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- .putExtra(Constants.KEY_LINK_TYPE, StreamingService.LinkType.STREAM)
- .putExtra(Constants.KEY_URL, this.player.getVideoUrl())
- .putExtra(Constants.KEY_TITLE, this.player.getVideoTitle())
- .putExtra(Constants.KEY_SERVICE_ID,
- this.player.getCurrentMetadata().getMetadata().getServiceId())
- .putExtra(VideoPlayer.PLAYER_TYPE, playerType);
- }
-
////////////////////////////////////////////////////////////////////////////
// Service Connection
////////////////////////////////////////////////////////////////////////////
@@ -367,7 +356,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
final MenuItem detail = popupMenu.getMenu().add(RECYCLER_ITEM_POPUP_MENU_GROUP_ID, 1,
Menu.NONE, R.string.play_queue_stream_detail);
detail.setOnMenuItemClickListener(menuItem -> {
- onOpenDetail(item.getServiceId(), item.getUrl(), item.getTitle());
+ // playQueue is null since we don't want any queue change
+ NavigationHelper.openVideoDetail(this, item.getServiceId(), item.getUrl(),
+ item.getTitle(), null, false);
return true;
});
@@ -454,11 +445,6 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
};
}
- private void onOpenDetail(final int serviceId, final String videoUrl,
- final String videoTitle) {
- NavigationHelper.openVideoDetail(this, serviceId, videoUrl, videoTitle);
- }
-
private void scrollToSelected() {
if (player == null) {
return;
diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
index 97007f0f6..fa016e158 100644
--- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
+++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
@@ -76,9 +76,7 @@ import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.nostra13.universalimageloader.core.assist.FailReason;
-import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
-import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
@@ -97,7 +95,6 @@ import org.schabi.newpipe.player.resolver.AudioPlaybackResolver;
import org.schabi.newpipe.player.resolver.MediaSourceTag;
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
import org.schabi.newpipe.util.AnimationUtils;
-import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper;
@@ -260,7 +257,12 @@ public class VideoPlayerImpl extends VideoPlayer
onQueueClosed();
// Android TV: without it focus will frame the whole player
playPauseButton.requestFocus();
- onPlay();
+
+ if (simpleExoPlayer.getPlayWhenReady()) {
+ onPlay();
+ } else {
+ onPause();
+ }
}
NavigationHelper.sendPlayerStartedEvent(service);
}
@@ -756,40 +758,6 @@ public class VideoPlayerImpl extends VideoPlayer
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
public void onClick(final View v) {
super.onClick(v);
@@ -817,7 +785,9 @@ public class VideoPlayerImpl extends VideoPlayer
} else if (v.getId() == openInBrowser.getId()) {
onOpenInBrowserClicked();
} else if (v.getId() == fullscreenButton.getId()) {
- switchFromPopupToMain();
+ setRecovery();
+ NavigationHelper.playOnMainPlayer(context, getPlayQueue(), true);
+ return;
} else if (v.getId() == screenRotationButton.getId()) {
// Only if it's not a vertical video or vertical video but in landscape with locked
// orientation a screen orientation can be changed automatically
diff --git a/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt
index dcc1bb128..681c1b9af 100644
--- a/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt
+++ b/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt
@@ -63,7 +63,7 @@ abstract class BasePlayerGestureListener(
private var isMovingInPopup = false
private var isResizing = false
- private val tossFlingVelocity = PlayerHelper.getTossFlingVelocity(service)
+ private val tossFlingVelocity = PlayerHelper.getTossFlingVelocity()
// [popup] initial coordinates and distance between fingers
private var initPointerDistance = -1.0
@@ -104,9 +104,6 @@ abstract class BasePlayerGestureListener(
}
private fun onTouchInPopup(v: View, event: MotionEvent): Boolean {
- if (playerImpl == null) {
- return false
- }
playerImpl.gestureDetector.onTouchEvent(event)
if (event.pointerCount == 2 && !isMovingInPopup && !isResizing) {
if (DEBUG) {
diff --git a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java
index a23d5d3ff..fdea20775 100644
--- a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java
+++ b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java
@@ -111,10 +111,10 @@ public class PlayerGestureListener
}
if (playerType == MainPlayer.PlayerType.VIDEO) {
if (portion == DisplayPortion.LEFT_HALF) {
- onScrollMainVolume(distanceX, distanceY);
+ onScrollMainBrightness(distanceX, distanceY);
} else /* DisplayPortion.RIGHT_HALF */ {
- onScrollMainBrightness(distanceX, distanceY);
+ onScrollMainVolume(distanceX, distanceY);
}
} else /* MainPlayer.PlayerType.POPUP */ {
diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java
index a931c46bd..ffe19599d 100644
--- a/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java
+++ b/app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java
@@ -164,7 +164,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, An
@Override
public void onAudioSessionId(final EventTime eventTime, final int audioSessionId) {
- if (!PlayerHelper.isUsingDSP(context)) {
+ if (!PlayerHelper.isUsingDSP()) {
return;
}
diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java
index 4b52aa27d..cdd07ba1c 100644
--- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java
+++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java
@@ -295,7 +295,7 @@ public final class PlayerHelper {
return 60000;
}
- public static TrackSelection.Factory getQualitySelector(@NonNull final Context context) {
+ public static TrackSelection.Factory getQualitySelector() {
return new AdaptiveTrackSelection.Factory(
1000,
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
@@ -303,11 +303,11 @@ public final class PlayerHelper {
AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION);
}
- public static boolean isUsingDSP(@NonNull final Context context) {
+ public static boolean isUsingDSP() {
return true;
}
- public static int getTossFlingVelocity(@NonNull final Context context) {
+ public static int getTossFlingVelocity() {
return 2500;
}
diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java
index 6d0f5fff7..854e3eb2b 100644
--- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java
+++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.java
@@ -49,6 +49,17 @@ public final class PlayerHolder {
return player.getPlayerType();
}
+ public static boolean isPlaying() {
+ if (player == null) {
+ return false;
+ }
+ return player.isPlaying();
+ }
+
+ public static boolean isPlayerOpen() {
+ return player != null;
+ }
+
public static void setListener(final PlayerServiceExtendedEventListener newListener) {
listener = newListener;
// Force reload data from service
diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java
index 4f35f98f5..b8bb677e0 100644
--- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java
+++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java
@@ -1,12 +1,8 @@
package org.schabi.newpipe.player.playqueue;
-import android.util.Log;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import org.reactivestreams.Subscriber;
-import org.reactivestreams.Subscription;
import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.player.playqueue.events.AppendEvent;
import org.schabi.newpipe.player.playqueue.events.ErrorEvent;
@@ -43,7 +39,6 @@ import io.reactivex.subjects.BehaviorSubject;
*