1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-26 10:00:39 +00:00

Autoplay enhancement and new button at the top left corner

- added a video close button to the top left corner
- autoplay will not work if stream plays in background or popup players
This commit is contained in:
Avently 2020-01-09 18:28:06 +03:00
parent 4c57893312
commit 22bb129bd9
5 changed files with 65 additions and 13 deletions

View File

@ -38,9 +38,9 @@
<service <service
android:name=".player.BackgroundPlayer" android:name=".player.BackgroundPlayer"
android:exported="false"> android:exported="false">
<intent-filter> <!--<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter> </intent-filter>-->
</service> </service>
<service <service

View File

@ -27,7 +27,6 @@ import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Html; import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
@ -111,6 +110,7 @@ public class VideoDetailFragment
private static final float MAX_OVERLAY_ALPHA = 0.9f; private static final float MAX_OVERLAY_ALPHA = 0.9f;
public static final String ACTION_SHOW_MAIN_PLAYER = "org.schabi.newpipe.fragments.VideoDetailFragment.ACTION_SHOW_MAIN_PLAYER"; public static final String ACTION_SHOW_MAIN_PLAYER = "org.schabi.newpipe.fragments.VideoDetailFragment.ACTION_SHOW_MAIN_PLAYER";
public static final String ACTION_HIDE_MAIN_PLAYER = "org.schabi.newpipe.fragments.VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER";
private boolean autoPlayEnabled; private boolean autoPlayEnabled;
private boolean showRelatedStreams; private boolean showRelatedStreams;
@ -549,7 +549,6 @@ public class VideoDetailFragment
setOverlayPlayPauseImage(); setOverlayPlayPauseImage();
break; break;
case R.id.overlay_close_button: case R.id.overlay_close_button:
cleanUp();
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
break; break;
} }
@ -874,6 +873,14 @@ public class VideoDetailFragment
return true; return true;
} }
StackItem currentPeek = stack.peek();
if (currentPeek != null && currentPeek.getPlayQueue() != playQueue) {
// When user selected a stream but didn't start playback this stream will not be added to backStack.
// Then he press Back and the last saved item from history will show up
setupFromHistoryItem(currentPeek);
return true;
}
// If we have something in history of played items we replay it here // If we have something in history of played items we replay it here
if (player != null && player.getPlayQueue() != null && player.getPlayQueue().previous()) { if (player != null && player.getPlayQueue() != null && player.getPlayQueue().previous()) {
return true; return true;
@ -888,18 +895,20 @@ public class VideoDetailFragment
// Remove top // Remove top
stack.pop(); stack.pop();
// Get stack item from the new top // Get stack item from the new top
StackItem peek = stack.peek(); setupFromHistoryItem(stack.peek());
return true;
}
private void setupFromHistoryItem(StackItem item) {
hideMainPlayer(); hideMainPlayer();
setAutoplay(false); setAutoplay(false);
selectAndLoadVideo( selectAndLoadVideo(
peek.getServiceId(), item.getServiceId(),
peek.getUrl(), item.getUrl(),
!TextUtils.isEmpty(peek.getTitle()) ? peek.getTitle() : "", !TextUtils.isEmpty(item.getTitle()) ? item.getTitle() : "",
peek.getPlayQueue()); item.getPlayQueue());
return true;
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -1165,6 +1174,7 @@ public class VideoDetailFragment
return playQueue != null && playQueue.getStreams().size() != 0 return playQueue != null && playQueue.getStreams().size() != 0
&& autoPlayEnabled && autoPlayEnabled
&& !isExternalPlayerEnabled() && !isExternalPlayerEnabled()
&& (player == null || player.videoPlayerSelected())
&& isAutoplayAllowedByUser(); && isAutoplayAllowedByUser();
} }
@ -1289,10 +1299,14 @@ public class VideoDetailFragment
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(ACTION_SHOW_MAIN_PLAYER)) { if(intent.getAction().equals(ACTION_SHOW_MAIN_PLAYER)) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else if(intent.getAction().equals(ACTION_HIDE_MAIN_PLAYER)) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
} }
} }
}; };
IntentFilter intentFilter = new IntentFilter(ACTION_SHOW_MAIN_PLAYER); IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION_SHOW_MAIN_PLAYER);
intentFilter.addAction(ACTION_HIDE_MAIN_PLAYER);
activity.registerReceiver(broadcastReceiver, intentFilter); activity.registerReceiver(broadcastReceiver, intentFilter);
} }
@ -1662,7 +1676,8 @@ public class VideoDetailFragment
public void onProgressUpdate(int currentProgress, int duration, int bufferPercent) { public void onProgressUpdate(int currentProgress, int duration, int bufferPercent) {
// Progress updates every second even if media is paused. It's useless until playing // Progress updates every second even if media is paused. It's useless until playing
if (!player.getPlayer().isPlaying() || playQueue == null) return; if (!player.getPlayer().isPlaying() || playQueue == null) return;
showPlaybackProgress(currentProgress, duration);
if (playQueue == player.getPlayQueue()) showPlaybackProgress(currentProgress, duration);
// We don't want to interrupt playback and don't want to see notification if player is stopped // We don't want to interrupt playback and don't want to see notification if player is stopped
// since next lines of code will enable background playback if needed // since next lines of code will enable background playback if needed

View File

@ -108,6 +108,7 @@ public class VideoPlayerImpl extends VideoPlayer
private ImageButton playWithKodi; private ImageButton playWithKodi;
private ImageButton openInBrowser; private ImageButton openInBrowser;
private ImageButton fullscreenButton; private ImageButton fullscreenButton;
private ImageButton playerCloseButton;
private ImageButton playPauseButton; private ImageButton playPauseButton;
private ImageButton playPreviousButton; private ImageButton playPreviousButton;
@ -238,6 +239,7 @@ public class VideoPlayerImpl extends VideoPlayer
this.playWithKodi = rootView.findViewById(R.id.playWithKodi); this.playWithKodi = rootView.findViewById(R.id.playWithKodi);
this.openInBrowser = rootView.findViewById(R.id.openInBrowser); this.openInBrowser = rootView.findViewById(R.id.openInBrowser);
this.fullscreenButton = rootView.findViewById(R.id.fullScreenButton); this.fullscreenButton = rootView.findViewById(R.id.fullScreenButton);
this.playerCloseButton = rootView.findViewById(R.id.playerCloseButton);
this.playPauseButton = rootView.findViewById(R.id.playPauseButton); this.playPauseButton = rootView.findViewById(R.id.playPauseButton);
this.playPreviousButton = rootView.findViewById(R.id.playPreviousButton); this.playPreviousButton = rootView.findViewById(R.id.playPreviousButton);
@ -293,6 +295,7 @@ public class VideoPlayerImpl extends VideoPlayer
shareButton.setVisibility(View.GONE); shareButton.setVisibility(View.GONE);
playWithKodi.setVisibility(View.GONE); playWithKodi.setVisibility(View.GONE);
openInBrowser.setVisibility(View.GONE); openInBrowser.setVisibility(View.GONE);
playerCloseButton.setVisibility(View.GONE);
} else { } else {
fullscreenButton.setVisibility(View.GONE); fullscreenButton.setVisibility(View.GONE);
getRootView().findViewById(R.id.spaceBeforeControls).setVisibility(View.VISIBLE); getRootView().findViewById(R.id.spaceBeforeControls).setVisibility(View.VISIBLE);
@ -307,6 +310,7 @@ public class VideoPlayerImpl extends VideoPlayer
playWithKodi.setVisibility( playWithKodi.setVisibility(
defaultPreferences.getBoolean(service.getString(R.string.show_play_with_kodi_key), false) ? View.VISIBLE : View.GONE); defaultPreferences.getBoolean(service.getString(R.string.show_play_with_kodi_key), false) ? View.VISIBLE : View.GONE);
openInBrowser.setVisibility(View.VISIBLE); openInBrowser.setVisibility(View.VISIBLE);
playerCloseButton.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
} }
if (!isInFullscreen()) { if (!isInFullscreen()) {
titleTextView.setVisibility(View.GONE); titleTextView.setVisibility(View.GONE);
@ -341,6 +345,7 @@ public class VideoPlayerImpl extends VideoPlayer
fullscreenButton.setOnClickListener(this); fullscreenButton.setOnClickListener(this);
playWithKodi.setOnClickListener(this); playWithKodi.setOnClickListener(this);
openInBrowser.setOnClickListener(this); openInBrowser.setOnClickListener(this);
playerCloseButton.setOnClickListener(this);
getRootView().addOnLayoutChangeListener((view, l, t, r, b, ol, ot, or, ob) -> { getRootView().addOnLayoutChangeListener((view, l, t, r, b, ol, ot, or, ob) -> {
if (l != ol || t != ot || r != or || b != ob) { if (l != ol || t != ot || r != or || b != ob) {
@ -555,9 +560,11 @@ public class VideoPlayerImpl extends VideoPlayer
if (!isInFullscreen()) { if (!isInFullscreen()) {
titleTextView.setVisibility(View.GONE); titleTextView.setVisibility(View.GONE);
channelTextView.setVisibility(View.GONE); channelTextView.setVisibility(View.GONE);
playerCloseButton.setVisibility(videoPlayerSelected() ? View.VISIBLE : View.GONE);
} else { } else {
titleTextView.setVisibility(View.VISIBLE); titleTextView.setVisibility(View.VISIBLE);
channelTextView.setVisibility(View.VISIBLE); channelTextView.setVisibility(View.VISIBLE);
playerCloseButton.setVisibility(View.GONE);
} }
} }
@ -597,6 +604,8 @@ public class VideoPlayerImpl extends VideoPlayer
} else if (v.getId() == fullscreenButton.getId()) { } else if (v.getId() == fullscreenButton.getId()) {
toggleFullscreen(); toggleFullscreen();
} else if (v.getId() == playerCloseButton.getId()) {
service.sendBroadcast(new Intent(VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER));
} }
if (getCurrentState() != STATE_COMPLETED) { if (getCurrentState() != STATE_COMPLETED) {

View File

@ -175,6 +175,20 @@
android:paddingLeft="2dp" android:paddingLeft="2dp"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<ImageButton
android:id="@+id/playerCloseButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="6dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
android:src="?attr/close"
android:background="?attr/selectableItemBackgroundBorderless"
tools:ignore="ContentDescription,RtlHardcoded"
android:visibility="gone" />
<LinearLayout <LinearLayout
android:id="@+id/metadataView" android:id="@+id/metadataView"
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -173,6 +173,20 @@
android:paddingLeft="2dp" android:paddingLeft="2dp"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<ImageButton
android:id="@+id/playerCloseButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:padding="6dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
android:src="?attr/close"
android:background="?attr/selectableItemBackgroundBorderless"
tools:ignore="ContentDescription,RtlHardcoded"
android:visibility="gone" />
<LinearLayout <LinearLayout
android:id="@+id/metadataView" android:id="@+id/metadataView"
android:layout_width="0dp" android:layout_width="0dp"