Skip to content

Commit

Permalink
Merge pull request TeamNewPipe/NewPipe#5371 from Stypox/merge-player
Browse files Browse the repository at this point in the history
Merge player classes into a single one
  • Loading branch information
Redirion authored and tossj committed Apr 11, 2021
1 parent d3565a7 commit 6dbf27a
Show file tree
Hide file tree
Showing 31 changed files with 4,558 additions and 5,259 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</service>

<activity
android:name=".player.BackgroundPlayerActivity"
android:name=".player.PlayQueueActivity"
android:label="@string/title_activity_play_queue"
android:launchMode="singleTask" />

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/schabi/newpipelegacy/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import org.schabi.newpipelegacy.fragments.MainFragment;
import org.schabi.newpipelegacy.fragments.detail.VideoDetailFragment;
import org.schabi.newpipelegacy.fragments.list.search.SearchFragment;
import org.schabi.newpipelegacy.player.VideoPlayer;
import org.schabi.newpipelegacy.player.Player;
import org.schabi.newpipelegacy.player.event.OnKeyDownListener;
import org.schabi.newpipelegacy.player.helper.PlayerHolder;
import org.schabi.newpipelegacy.player.playqueue.PlayQueue;
Expand Down Expand Up @@ -761,7 +761,7 @@ private void handleIntent(final Intent intent) {
switch (linkType) {
case STREAM:
final String intentCacheKey = intent.getStringExtra(
VideoPlayer.PLAY_QUEUE_KEY);
Player.PLAY_QUEUE_KEY);
final PlayQueue playQueue = intentCacheKey != null
? SerializedCache.getInstance()
.take(intentCacheKey, PlayQueue.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@

import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.tabs.TabLayout;
Expand Down Expand Up @@ -81,9 +80,8 @@
import org.schabi.newpipelegacy.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipelegacy.local.dialog.PlaylistCreationDialog;
import org.schabi.newpipelegacy.local.history.HistoryRecordManager;
import org.schabi.newpipelegacy.player.BasePlayer;
import org.schabi.newpipelegacy.player.Player;
import org.schabi.newpipelegacy.player.MainPlayer;
import org.schabi.newpipelegacy.player.VideoPlayerImpl;
import org.schabi.newpipelegacy.player.event.OnKeyDownListener;
import org.schabi.newpipelegacy.player.event.PlayerServiceExtendedEventListener;
import org.schabi.newpipelegacy.player.helper.PlayerHelper;
Expand Down Expand Up @@ -256,14 +254,14 @@ public final class VideoDetailFragment

private ContentObserver settingsContentObserver;
private MainPlayer playerService;
private VideoPlayerImpl player;
private Player player;


/*//////////////////////////////////////////////////////////////////////////
// Service management
//////////////////////////////////////////////////////////////////////////*/
@Override
public void onServiceConnected(final VideoPlayerImpl connectedPlayer,
public void onServiceConnected(final Player connectedPlayer,
final MainPlayer connectedPlayerService,
final boolean playAfterConnect) {
player = connectedPlayer;
Expand Down Expand Up @@ -540,7 +538,7 @@ public void onClick(final View v) {
break;
case R.id.overlay_play_pause_button:
if (playerIsNotStopped()) {
player.onPlayPause();
player.playPause();
player.hideControls(0, 0);
showSystemUi();
} else {
Expand Down Expand Up @@ -806,7 +804,7 @@ public boolean onBackPressed() {
// If we are in fullscreen mode just exit from it via first back press
if (player != null && player.isFullscreen()) {
if (!DeviceUtils.isTablet(activity)) {
player.onPause();
player.pause();
}
restoreDefaultOrientation();
setAutoPlay(false);
Expand Down Expand Up @@ -851,7 +849,7 @@ private void setupFromHistoryItem(final StackItem item) {

final PlayQueueItem playQueueItem = item.getPlayQueue().getItem();
// Update title, url, uploader from the last item in the stack (it's current now)
final boolean isPlayerStopped = player == null || player.isPlayerStopped();
final boolean isPlayerStopped = player == null || player.isStopped();
if (playQueueItem != null && isPlayerStopped) {
updateOverlayData(playQueueItem.getTitle(),
playQueueItem.getUploader(), playQueueItem.getThumbnailUrl());
Expand Down Expand Up @@ -1570,7 +1568,7 @@ public void handleResult(@NonNull final StreamInfo info) {
showMetaInfoInTextView(info.getMetaInfo(), detailMetaInfoTextView, detailMetaInfoSeparator);


if (player == null || player.isPlayerStopped()) {
if (player == null || player.isStopped()) {
updateOverlayData(info.getName(), info.getUploaderName(), info.getThumbnailUrl());
}

Expand Down Expand Up @@ -1799,7 +1797,7 @@ public void onPlaybackUpdate(final int state,
setOverlayPlayPauseImage(player != null && player.isPlaying());

switch (state) {
case BasePlayer.STATE_PLAYING:
case Player.STATE_PLAYING:
if (positionView.getAlpha() != 1.0f
&& player.getPlayQueue() != null
&& player.getPlayQueue().getItem() != null
Expand All @@ -1816,7 +1814,7 @@ public void onProgressUpdate(final int currentProgress,
final int duration,
final int bufferPercent) {
// Progress updates every second even if media is paused. It's useless until playing
if (!player.getPlayer().isPlaying() || playQueue == null) {
if (!player.isPlaying() || playQueue == null) {
return;
}

Expand Down Expand Up @@ -1893,10 +1891,8 @@ public void onFullscreenStateChanged(final boolean fullscreen) {

if (fullscreen) {
hideSystemUiIfNeeded();
viewPager.setVisibility(View.GONE);
} else {
showSystemUi();
viewPager.setVisibility(View.VISIBLE);
}

if (relatedStreamsLayout != null) {
Expand Down Expand Up @@ -2025,9 +2021,7 @@ public void hideSystemUiIfNeeded() {
}

private boolean playerIsNotStopped() {
return player != null
&& player.getPlayer() != null
&& player.getPlayer().getPlaybackState() != Player.STATE_IDLE;
return player != null && !player.isStopped();
}

private void restoreDefaultBrightness() {
Expand Down Expand Up @@ -2078,7 +2072,7 @@ private void checkLandscape() {
player.checkLandscape();
// Let's give a user time to look at video information page if video is not playing
if (globalScreenOrientationLocked(activity) && !player.isPlaying()) {
player.onPlay();
player.play();
}
}

Expand Down Expand Up @@ -2292,7 +2286,7 @@ public void onStateChanged(@NonNull final View bottomSheet, final int newState)
// Re-enable clicks
setOverlayElementsClickable(true);
if (player != null) {
player.onQueueClosed();
player.closeQueue();
}
setOverlayLook(appBarLayout, behavior, 0);
break;
Expand Down

This file was deleted.

Loading

0 comments on commit 6dbf27a

Please sign in to comment.