-Added fast seeking on background notification when play queue size is 1.

-Fixed player intent with quality selection not used in detail fragment.
-Fixed window index not reset on sync when not playing.
-Fix dropdown play string for stream info item.
This commit is contained in:
John Zhen Mo 2017-11-02 12:30:26 -07:00
parent b8a17580c5
commit 1d136c6c35
4 changed files with 46 additions and 21 deletions

View file

@ -66,6 +66,7 @@ import org.schabi.newpipe.info_list.InfoItemBuilder;
import org.schabi.newpipe.player.BackgroundPlayer; import org.schabi.newpipe.player.BackgroundPlayer;
import org.schabi.newpipe.player.MainVideoPlayer; import org.schabi.newpipe.player.MainVideoPlayer;
import org.schabi.newpipe.player.PopupVideoPlayer; import org.schabi.newpipe.player.PopupVideoPlayer;
import org.schabi.newpipe.player.helper.PlayerHelper;
import org.schabi.newpipe.player.old.PlayVideoActivity; import org.schabi.newpipe.player.old.PlayVideoActivity;
import org.schabi.newpipe.playlist.PlayQueue; import org.schabi.newpipe.playlist.PlayQueue;
import org.schabi.newpipe.playlist.SinglePlayQueue; import org.schabi.newpipe.playlist.SinglePlayQueue;
@ -800,7 +801,11 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
if (append) { if (append) {
NavigationHelper.enqueueOnPopupPlayer(activity, itemQueue); NavigationHelper.enqueueOnPopupPlayer(activity, itemQueue);
} else { } else {
NavigationHelper.playOnPopupPlayer(activity, itemQueue); Toast.makeText(activity, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
final Intent intent = NavigationHelper.getPlayerIntent(
activity, PopupVideoPlayer.class, itemQueue, getSelectedVideoStream().resolution
);
activity.startService(intent);
} }
} }
@ -863,20 +868,21 @@ public class VideoDetailFragment extends BaseStateFragment<StreamInfo> implement
} }
private void openNormalPlayer(VideoStream selectedVideoStream) { private void openNormalPlayer(VideoStream selectedVideoStream) {
boolean useOldPlayer = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(getString(R.string.use_old_player_key), false) Intent mIntent;
|| (Build.VERSION.SDK_INT < 16); boolean useOldPlayer = PlayerHelper.isUsingOldPlayer(activity) || (Build.VERSION.SDK_INT < 16);
if (!useOldPlayer) { if (!useOldPlayer) {
// ExoPlayer // ExoPlayer
NavigationHelper.playOnMainPlayer(activity, new SinglePlayQueue(currentInfo)); final PlayQueue playQueue = new SinglePlayQueue(currentInfo);
mIntent = NavigationHelper.getPlayerIntent(activity, MainVideoPlayer.class, playQueue, getSelectedVideoStream().resolution);
} else { } else {
// Internal Player // Internal Player
final Intent mIntent = new Intent(activity, PlayVideoActivity.class) mIntent = new Intent(activity, PlayVideoActivity.class)
.putExtra(PlayVideoActivity.VIDEO_TITLE, currentInfo.name) .putExtra(PlayVideoActivity.VIDEO_TITLE, currentInfo.name)
.putExtra(PlayVideoActivity.STREAM_URL, selectedVideoStream.url) .putExtra(PlayVideoActivity.STREAM_URL, selectedVideoStream.url)
.putExtra(PlayVideoActivity.VIDEO_URL, currentInfo.url) .putExtra(PlayVideoActivity.VIDEO_URL, currentInfo.url)
.putExtra(PlayVideoActivity.START_POSITION, currentInfo.start_position); .putExtra(PlayVideoActivity.START_POSITION, currentInfo.start_position);
startActivity(mIntent);
} }
startActivity(mIntent);
} }
private void openExternalVideoPlayer(VideoStream selectedVideoStream) { private void openExternalVideoPlayer(VideoStream selectedVideoStream) {

View file

@ -133,7 +133,7 @@ public class StreamMiniInfoItemHolder extends InfoItemHolder {
} }
}); });
final MenuItem mainPlay = actionMenu.getMenu().add(R.string.play_all); final MenuItem mainPlay = actionMenu.getMenu().add(R.string.play_btn_text);
mainPlay.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { mainPlay.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem menuItem) { public boolean onMenuItemClick(MenuItem menuItem) {

View file

@ -69,6 +69,10 @@ public final class BackgroundPlayer extends Service {
public static final String ACTION_REPEAT = "org.schabi.newpipe.player.BackgroundPlayer.REPEAT"; public static final String ACTION_REPEAT = "org.schabi.newpipe.player.BackgroundPlayer.REPEAT";
public static final String ACTION_PLAY_NEXT = "org.schabi.newpipe.player.BackgroundPlayer.ACTION_PLAY_NEXT"; public static final String ACTION_PLAY_NEXT = "org.schabi.newpipe.player.BackgroundPlayer.ACTION_PLAY_NEXT";
public static final String ACTION_PLAY_PREVIOUS = "org.schabi.newpipe.player.BackgroundPlayer.ACTION_PLAY_PREVIOUS"; public static final String ACTION_PLAY_PREVIOUS = "org.schabi.newpipe.player.BackgroundPlayer.ACTION_PLAY_PREVIOUS";
public static final String ACTION_FAST_REWIND = "org.schabi.newpipe.player.BackgroundPlayer.ACTION_FAST_REWIND";
public static final String ACTION_FAST_FORWARD = "org.schabi.newpipe.player.BackgroundPlayer.ACTION_FAST_FORWARD";
public static final String SET_IMAGE_RESOURCE_METHOD = "setImageResource";
private BasePlayerImpl basePlayerImpl; private BasePlayerImpl basePlayerImpl;
private LockManager lockManager; private LockManager lockManager;
@ -182,6 +186,8 @@ public final class BackgroundPlayer extends Service {
} }
private void setupNotification(RemoteViews remoteViews) { private void setupNotification(RemoteViews remoteViews) {
if (basePlayerImpl == null) return;
remoteViews.setTextViewText(R.id.notificationSongName, basePlayerImpl.getVideoTitle()); remoteViews.setTextViewText(R.id.notificationSongName, basePlayerImpl.getVideoTitle());
remoteViews.setTextViewText(R.id.notificationArtist, basePlayerImpl.getUploaderName()); remoteViews.setTextViewText(R.id.notificationArtist, basePlayerImpl.getUploaderName());
@ -194,10 +200,21 @@ public final class BackgroundPlayer extends Service {
remoteViews.setOnClickPendingIntent(R.id.notificationRepeat, remoteViews.setOnClickPendingIntent(R.id.notificationRepeat,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_REPEAT), PendingIntent.FLAG_UPDATE_CURRENT)); PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_REPEAT), PendingIntent.FLAG_UPDATE_CURRENT));
if (basePlayerImpl.playQueue != null && basePlayerImpl.playQueue.size() > 1) {
remoteViews.setInt(R.id.notificationFRewind, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_previous);
remoteViews.setInt(R.id.notificationFForward, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_next);
remoteViews.setOnClickPendingIntent(R.id.notificationFRewind, remoteViews.setOnClickPendingIntent(R.id.notificationFRewind,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT)); PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT));
remoteViews.setOnClickPendingIntent(R.id.notificationFForward, remoteViews.setOnClickPendingIntent(R.id.notificationFForward,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT)); PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT));
} else {
remoteViews.setInt(R.id.notificationFRewind, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_rewind);
remoteViews.setInt(R.id.notificationFForward, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_fastforward);
remoteViews.setOnClickPendingIntent(R.id.notificationFRewind,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_REWIND), PendingIntent.FLAG_UPDATE_CURRENT));
remoteViews.setOnClickPendingIntent(R.id.notificationFForward,
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT));
}
setRepeatModeIcon(remoteViews, basePlayerImpl.getRepeatMode()); setRepeatModeIcon(remoteViews, basePlayerImpl.getRepeatMode());
} }
@ -232,17 +249,15 @@ public final class BackgroundPlayer extends Service {
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
private void setRepeatModeIcon(final RemoteViews remoteViews, final int repeatMode) { private void setRepeatModeIcon(final RemoteViews remoteViews, final int repeatMode) {
final String methodName = "setImageResource";
switch (repeatMode) { switch (repeatMode) {
case Player.REPEAT_MODE_OFF: case Player.REPEAT_MODE_OFF:
remoteViews.setInt(R.id.notificationRepeat, methodName, R.drawable.exo_controls_repeat_off); remoteViews.setInt(R.id.notificationRepeat, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_repeat_off);
break; break;
case Player.REPEAT_MODE_ONE: case Player.REPEAT_MODE_ONE:
remoteViews.setInt(R.id.notificationRepeat, methodName, R.drawable.exo_controls_repeat_one); remoteViews.setInt(R.id.notificationRepeat, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_repeat_one);
break; break;
case Player.REPEAT_MODE_ALL: case Player.REPEAT_MODE_ALL:
remoteViews.setInt(R.id.notificationRepeat, methodName, R.drawable.exo_controls_repeat_all); remoteViews.setInt(R.id.notificationRepeat, SET_IMAGE_RESOURCE_METHOD, R.drawable.exo_controls_repeat_all);
break; break;
} }
} }
@ -441,6 +456,8 @@ public final class BackgroundPlayer extends Service {
intentFilter.addAction(ACTION_REPEAT); intentFilter.addAction(ACTION_REPEAT);
intentFilter.addAction(ACTION_PLAY_PREVIOUS); intentFilter.addAction(ACTION_PLAY_PREVIOUS);
intentFilter.addAction(ACTION_PLAY_NEXT); intentFilter.addAction(ACTION_PLAY_NEXT);
intentFilter.addAction(ACTION_FAST_REWIND);
intentFilter.addAction(ACTION_FAST_FORWARD);
intentFilter.addAction(Intent.ACTION_SCREEN_ON); intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF); intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
@ -472,6 +489,12 @@ public final class BackgroundPlayer extends Service {
case ACTION_PLAY_PREVIOUS: case ACTION_PLAY_PREVIOUS:
onPlayPrevious(); onPlayPrevious();
break; break;
case ACTION_FAST_FORWARD:
onFastForward();
break;
case ACTION_FAST_REWIND:
onFastRewind();
break;
case Intent.ACTION_SCREEN_ON: case Intent.ACTION_SCREEN_ON:
onScreenOnOff(true); onScreenOnOff(true);
break; break;

View file

@ -646,7 +646,7 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
if (currentSourceIndex != playQueue.getIndex()) { if (currentSourceIndex != playQueue.getIndex()) {
Log.e(TAG, "Play Queue may be desynchronized: item index=[" + currentSourceIndex + Log.e(TAG, "Play Queue may be desynchronized: item index=[" + currentSourceIndex +
"], queue index=[" + playQueue.getIndex() + "]"); "], queue index=[" + playQueue.getIndex() + "]");
} else if (simpleExoPlayer.getCurrentWindowIndex() != currentSourceIndex) { } else if (simpleExoPlayer.getCurrentWindowIndex() != currentSourceIndex || !isPlaying()) {
final long startPos = info != null ? info.start_position : 0; final long startPos = info != null ? info.start_position : 0;
if (DEBUG) Log.d(TAG, "Rewinding to correct window: " + currentSourceIndex + " at: " + getTimeString((int)startPos)); if (DEBUG) Log.d(TAG, "Rewinding to correct window: " + currentSourceIndex + " at: " + getTimeString((int)startPos));
simpleExoPlayer.seekTo(currentSourceIndex, startPos); simpleExoPlayer.seekTo(currentSourceIndex, startPos);
@ -761,10 +761,6 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
} else { } else {
playQueue.setIndex(index); playQueue.setIndex(index);
} }
if (!isPlaying()) {
onVideoPlayPause();
}
} }
public void seekBy(int milliSeconds) { public void seekBy(int milliSeconds) {