Skip to content

Commit

Permalink
Merge player classes into a single one
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jan 8, 2021
1 parent 6b2f084 commit d726546
Show file tree
Hide file tree
Showing 25 changed files with 4,645 additions and 5,311 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Expand Up @@ -68,7 +68,7 @@
import org.schabi.newpipe.fragments.MainFragment;
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.Player;
import org.schabi.newpipe.player.event.OnKeyDownListener;
import org.schabi.newpipe.player.helper.PlayerHolder;
import org.schabi.newpipe.player.playqueue.PlayQueue;
Expand Down Expand Up @@ -763,7 +763,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
Expand Up @@ -49,7 +49,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 @@ -80,9 +79,8 @@
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.dialog.PlaylistCreationDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.BasePlayer;
import org.schabi.newpipe.player.Player;
import org.schabi.newpipe.player.MainPlayer;
import org.schabi.newpipe.player.VideoPlayerImpl;
import org.schabi.newpipe.player.event.OnKeyDownListener;
import org.schabi.newpipe.player.event.PlayerServiceExtendedEventListener;
import org.schabi.newpipe.player.helper.PlayerHelper;
Expand Down Expand Up @@ -255,14 +253,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 @@ -539,7 +537,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 @@ -805,7 +803,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 @@ -850,7 +848,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 @@ -1569,7 +1567,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 @@ -1797,7 +1795,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 @@ -1814,7 +1812,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 @@ -2020,9 +2018,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 @@ -2073,7 +2069,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 @@ -2287,7 +2283,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
Expand Up @@ -26,15 +26,15 @@ public Intent getBindIntent() {

@Override
public void startPlayerListener() {
if (player instanceof VideoPlayerImpl) {
((VideoPlayerImpl) player).setActivityListener(this);
if (player != null) {
player.setActivityListener(this);
}
}

@Override
public void stopPlayerListener() {
if (player instanceof VideoPlayerImpl) {
((VideoPlayerImpl) player).removeActivityListener(this);
if (player != null) {
player.removeActivityListener(this);
}
}

Expand All @@ -45,13 +45,11 @@ public int getPlayerOptionMenuResource() {

@Override
public void setupMenu(final Menu menu) {
if (player == null) {
return;
if (player != null) {
menu.findItem(R.id.action_switch_popup)
.setVisible(!player.popupPlayerSelected());
menu.findItem(R.id.action_switch_background)
.setVisible(!player.audioPlayerSelected());
}

menu.findItem(R.id.action_switch_popup)
.setVisible(!((VideoPlayerImpl) player).popupPlayerSelected());
menu.findItem(R.id.action_switch_background)
.setVisible(!((VideoPlayerImpl) player).audioPlayerSelected());
}
}

0 comments on commit d726546

Please sign in to comment.