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";
static final String 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
= "org.schabi.newpipe.player.MainPlayer.ACTION_SHUFFLE";
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 com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
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_FAST_FORWARD;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND;
@ -147,9 +146,19 @@ public final class NotificationUtil {
}
boolean hasSlotWithBuffering() {
return notificationSlots[1] == NotificationConstants.PLAY_PAUSE_BUFFERING
|| notificationSlots[2] == NotificationConstants.PLAY_PAUSE_BUFFERING;
@SuppressLint("RestrictedApi")
boolean shouldUpdateBufferingSlot() {
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
|| player.getCurrentState() == BasePlayer.STATE_BLOCKED
|| player.getCurrentState() == BasePlayer.STATE_BUFFERING) {
return getAction(player, R.drawable.ic_hourglass_top_white_24dp_png,
R.string.notification_action_buffering, ACTION_BUFFERING);
// null intent -> show hourglass icon that does nothing when clicked
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()) {
return getAction(player, R.drawable.exo_notification_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.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_FAST_FORWARD;
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 fragmentIsVisible = false;
boolean shouldUpdateOnProgress;
private boolean isForwardPressed;
private boolean isRewindPressed;
private final MainPlayer service;
private PlayerServiceEventListener fragmentListener;
@ -1081,18 +1078,10 @@ public class VideoPlayerImpl extends VideoPlayer
super.onBuffering();
getRootView().setKeepScreenOn(true);
if (NotificationUtil.getInstance().hasSlotWithBuffering()
&& (getCurrentState() == BasePlayer.STATE_PREFLIGHT
|| getCurrentState() == BasePlayer.STATE_BLOCKED
|| getCurrentState() == BasePlayer.STATE_BUFFERING)) {
if (isForwardPressed || isRewindPressed) {
isForwardPressed = false;
isRewindPressed = false;
} else {
if (NotificationUtil.getInstance().shouldUpdateBufferingSlot()) {
NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, false);
}
}
}
@Override
public void onPlaying() {
@ -1186,7 +1175,6 @@ public class VideoPlayerImpl extends VideoPlayer
intentFilter.addAction(ACTION_PLAY_NEXT);
intentFilter.addAction(ACTION_FAST_REWIND);
intentFilter.addAction(ACTION_FAST_FORWARD);
intentFilter.addAction(ACTION_BUFFERING);
intentFilter.addAction(ACTION_SHUFFLE);
intentFilter.addAction(ACTION_RECREATE_NOTIFICATION);
@ -1222,11 +1210,9 @@ public class VideoPlayerImpl extends VideoPlayer
onPlayPrevious();
break;
case ACTION_FAST_FORWARD:
isForwardPressed = true;
onFastForward();
break;
case ACTION_FAST_REWIND:
isRewindPressed = true;
onFastRewind();
break;
case ACTION_PLAY_PAUSE:
@ -1240,9 +1226,6 @@ public class VideoPlayerImpl extends VideoPlayer
case ACTION_REPEAT:
onRepeatClicked();
break;
case ACTION_BUFFERING:
onBuffering();
break;
case ACTION_SHUFFLE:
onShuffleClicked();
break;