Remove ACTION_BUFFERING, update buffering only if needed

- ACTION_BUFFERING was just wrong: why should the user be able to trigger the internal onBuffering() state by pressing on the buffering button? So that was replaced by a null intent, doing nothing.
- Now updating notification in onBuffering() only when buffering actions are not already buffering, to prevent useless updates
This commit is contained in:
Stypox 2020-09-22 17:36:39 +02:00
parent 11e048abb1
commit 814efbf8df
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 19 additions and 27 deletions

View File

@ -76,8 +76,6 @@ public final class MainPlayer extends Service {
= "org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND"; = "org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND";
static final String ACTION_FAST_FORWARD static final String ACTION_FAST_FORWARD
= "org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD"; = "org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD";
static final String ACTION_BUFFERING
= "org.schabi.newpipe.player.MainPlayer.ACTION_BUFFERING";
static final String ACTION_SHUFFLE static final String ACTION_SHUFFLE
= "org.schabi.newpipe.player.MainPlayer.ACTION_SHUFFLE"; = "org.schabi.newpipe.player.MainPlayer.ACTION_SHUFFLE";
public static final String ACTION_RECREATE_NOTIFICATION public static final String ACTION_RECREATE_NOTIFICATION

View File

@ -26,7 +26,6 @@ import java.util.List;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL; import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE; import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
import static org.schabi.newpipe.player.MainPlayer.ACTION_BUFFERING;
import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE; import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD; import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND; import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND;
@ -147,9 +146,19 @@ public final class NotificationUtil {
} }
boolean hasSlotWithBuffering() { @SuppressLint("RestrictedApi")
return notificationSlots[1] == NotificationConstants.PLAY_PAUSE_BUFFERING boolean shouldUpdateBufferingSlot() {
|| notificationSlots[2] == NotificationConstants.PLAY_PAUSE_BUFFERING; if (notificationBuilder.mActions.size() < 3) {
// this should never happen, but let's make sure notification actions are populated
return true;
}
// only second and third slot could contain PLAY_PAUSE_BUFFERING, update them only if they
// are not already in the buffering state (the only one with a null action intent)
return (notificationSlots[1] == NotificationConstants.PLAY_PAUSE_BUFFERING
&& notificationBuilder.mActions.get(1).actionIntent != null)
|| (notificationSlots[2] == NotificationConstants.PLAY_PAUSE_BUFFERING
&& notificationBuilder.mActions.get(2).actionIntent != null);
} }
@ -264,8 +273,10 @@ public final class NotificationUtil {
if (player.getCurrentState() == BasePlayer.STATE_PREFLIGHT if (player.getCurrentState() == BasePlayer.STATE_PREFLIGHT
|| player.getCurrentState() == BasePlayer.STATE_BLOCKED || player.getCurrentState() == BasePlayer.STATE_BLOCKED
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING) { || player.getCurrentState() == BasePlayer.STATE_BUFFERING) {
return getAction(player, R.drawable.ic_hourglass_top_white_24dp_png, // null intent -> show hourglass icon that does nothing when clicked
R.string.notification_action_buffering, ACTION_BUFFERING); return new NotificationCompat.Action(R.drawable.ic_hourglass_top_white_24dp_png,
player.context.getString(R.string.notification_action_buffering),
null);
} else if (player.isPlaying()) { } else if (player.isPlaying()) {
return getAction(player, R.drawable.exo_notification_pause, return getAction(player, R.drawable.exo_notification_pause,
R.string.exo_controls_pause_description, ACTION_PLAY_PAUSE); R.string.exo_controls_pause_description, ACTION_PLAY_PAUSE);

View File

@ -105,7 +105,6 @@ import java.util.List;
import static android.content.Context.WINDOW_SERVICE; import static android.content.Context.WINDOW_SERVICE;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static org.schabi.newpipe.player.MainPlayer.ACTION_BUFFERING;
import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE; import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD; import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND; import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND;
@ -191,8 +190,6 @@ public class VideoPlayerImpl extends VideoPlayer
private boolean isVerticalVideo = false; private boolean isVerticalVideo = false;
private boolean fragmentIsVisible = false; private boolean fragmentIsVisible = false;
boolean shouldUpdateOnProgress; boolean shouldUpdateOnProgress;
private boolean isForwardPressed;
private boolean isRewindPressed;
private final MainPlayer service; private final MainPlayer service;
private PlayerServiceEventListener fragmentListener; private PlayerServiceEventListener fragmentListener;
@ -1081,18 +1078,10 @@ public class VideoPlayerImpl extends VideoPlayer
super.onBuffering(); super.onBuffering();
getRootView().setKeepScreenOn(true); getRootView().setKeepScreenOn(true);
if (NotificationUtil.getInstance().hasSlotWithBuffering() if (NotificationUtil.getInstance().shouldUpdateBufferingSlot()) {
&& (getCurrentState() == BasePlayer.STATE_PREFLIGHT
|| getCurrentState() == BasePlayer.STATE_BLOCKED
|| getCurrentState() == BasePlayer.STATE_BUFFERING)) {
if (isForwardPressed || isRewindPressed) {
isForwardPressed = false;
isRewindPressed = false;
} else {
NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, false); NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, false);
} }
} }
}
@Override @Override
public void onPlaying() { public void onPlaying() {
@ -1186,7 +1175,6 @@ public class VideoPlayerImpl extends VideoPlayer
intentFilter.addAction(ACTION_PLAY_NEXT); intentFilter.addAction(ACTION_PLAY_NEXT);
intentFilter.addAction(ACTION_FAST_REWIND); intentFilter.addAction(ACTION_FAST_REWIND);
intentFilter.addAction(ACTION_FAST_FORWARD); intentFilter.addAction(ACTION_FAST_FORWARD);
intentFilter.addAction(ACTION_BUFFERING);
intentFilter.addAction(ACTION_SHUFFLE); intentFilter.addAction(ACTION_SHUFFLE);
intentFilter.addAction(ACTION_RECREATE_NOTIFICATION); intentFilter.addAction(ACTION_RECREATE_NOTIFICATION);
@ -1222,11 +1210,9 @@ public class VideoPlayerImpl extends VideoPlayer
onPlayPrevious(); onPlayPrevious();
break; break;
case ACTION_FAST_FORWARD: case ACTION_FAST_FORWARD:
isForwardPressed = true;
onFastForward(); onFastForward();
break; break;
case ACTION_FAST_REWIND: case ACTION_FAST_REWIND:
isRewindPressed = true;
onFastRewind(); onFastRewind();
break; break;
case ACTION_PLAY_PAUSE: case ACTION_PLAY_PAUSE:
@ -1240,9 +1226,6 @@ public class VideoPlayerImpl extends VideoPlayer
case ACTION_REPEAT: case ACTION_REPEAT:
onRepeatClicked(); onRepeatClicked();
break; break;
case ACTION_BUFFERING:
onBuffering();
break;
case ACTION_SHUFFLE: case ACTION_SHUFFLE:
onShuffleClicked(); onShuffleClicked();
break; break;