Merge pull request #3437 from TheLastGimbus/fast-rewind-forward-in-background-activity

Fast rewind forward in background activity
This commit is contained in:
wb9688 2020-06-15 15:06:58 +02:00 committed by GitHub
commit e6fe6fd645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 65 deletions

View file

@ -1131,6 +1131,7 @@ public abstract class BasePlayer implements
Log.d(TAG, "onFastRewind() called"); Log.d(TAG, "onFastRewind() called");
} }
seekBy(-getSeekDuration()); seekBy(-getSeekDuration());
triggerProgressUpdate();
} }
public void onFastForward() { public void onFastForward() {
@ -1138,6 +1139,7 @@ public abstract class BasePlayer implements
Log.d(TAG, "onFastForward() called"); Log.d(TAG, "onFastForward() called");
} }
seekBy(getSeekDuration()); seekBy(getSeekDuration());
triggerProgressUpdate();
} }
private int getSeekDuration() { private int getSeekDuration() {

View file

@ -45,7 +45,6 @@ import org.schabi.newpipe.util.ThemeHelper;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.schabi.newpipe.player.helper.PlayerHelper.formatPitch;
import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed; import static org.schabi.newpipe.player.helper.PlayerHelper.formatSpeed;
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
@ -84,14 +83,13 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private ImageButton repeatButton; private ImageButton repeatButton;
private ImageButton backwardButton; private ImageButton backwardButton;
private ImageButton fastRewindButton;
private ImageButton playPauseButton; private ImageButton playPauseButton;
private ImageButton fastForwardButton;
private ImageButton forwardButton; private ImageButton forwardButton;
private ImageButton shuffleButton; private ImageButton shuffleButton;
private ProgressBar progressBar; private ProgressBar progressBar;
private TextView playbackSpeedButton;
private TextView playbackPitchButton;
private Menu menu; private Menu menu;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -166,6 +164,9 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
case R.id.action_append_playlist: case R.id.action_append_playlist:
appendAllToPlaylist(); appendAllToPlaylist();
return true; return true;
case R.id.action_playback_speed:
openPlaybackParameterDialog();
return true;
case R.id.action_mute: case R.id.action_mute:
player.onMuteUnmuteButtonClicked(); player.onMuteUnmuteButtonClicked();
return true; return true;
@ -310,20 +311,20 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private void buildControls() { private void buildControls() {
repeatButton = rootView.findViewById(R.id.control_repeat); repeatButton = rootView.findViewById(R.id.control_repeat);
backwardButton = rootView.findViewById(R.id.control_backward); backwardButton = rootView.findViewById(R.id.control_backward);
fastRewindButton = rootView.findViewById(R.id.control_fast_rewind);
playPauseButton = rootView.findViewById(R.id.control_play_pause); playPauseButton = rootView.findViewById(R.id.control_play_pause);
fastForwardButton = rootView.findViewById(R.id.control_fast_forward);
forwardButton = rootView.findViewById(R.id.control_forward); forwardButton = rootView.findViewById(R.id.control_forward);
shuffleButton = rootView.findViewById(R.id.control_shuffle); shuffleButton = rootView.findViewById(R.id.control_shuffle);
playbackSpeedButton = rootView.findViewById(R.id.control_playback_speed);
playbackPitchButton = rootView.findViewById(R.id.control_playback_pitch);
progressBar = rootView.findViewById(R.id.control_progress_bar); progressBar = rootView.findViewById(R.id.control_progress_bar);
repeatButton.setOnClickListener(this); repeatButton.setOnClickListener(this);
backwardButton.setOnClickListener(this); backwardButton.setOnClickListener(this);
fastRewindButton.setOnClickListener(this);
playPauseButton.setOnClickListener(this); playPauseButton.setOnClickListener(this);
fastForwardButton.setOnClickListener(this);
forwardButton.setOnClickListener(this); forwardButton.setOnClickListener(this);
shuffleButton.setOnClickListener(this); shuffleButton.setOnClickListener(this);
playbackSpeedButton.setOnClickListener(this);
playbackPitchButton.setOnClickListener(this);
} }
private void buildItemPopupMenu(final PlayQueueItem item, final View view) { private void buildItemPopupMenu(final PlayQueueItem item, final View view) {
@ -473,16 +474,16 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
player.onRepeatClicked(); player.onRepeatClicked();
} else if (view.getId() == backwardButton.getId()) { } else if (view.getId() == backwardButton.getId()) {
player.onPlayPrevious(); player.onPlayPrevious();
} else if (view.getId() == fastRewindButton.getId()) {
player.onFastRewind();
} else if (view.getId() == playPauseButton.getId()) { } else if (view.getId() == playPauseButton.getId()) {
player.onPlayPause(); player.onPlayPause();
} else if (view.getId() == fastForwardButton.getId()) {
player.onFastForward();
} else if (view.getId() == forwardButton.getId()) { } else if (view.getId() == forwardButton.getId()) {
player.onPlayNext(); player.onPlayNext();
} else if (view.getId() == shuffleButton.getId()) { } else if (view.getId() == shuffleButton.getId()) {
player.onShuffleClicked(); player.onShuffleClicked();
} else if (view.getId() == playbackSpeedButton.getId()) {
openPlaybackParameterDialog();
} else if (view.getId() == playbackPitchButton.getId()) {
openPlaybackParameterDialog();
} else if (view.getId() == metadata.getId()) { } else if (view.getId() == metadata.getId()) {
scrollToSelected(); scrollToSelected();
} else if (view.getId() == progressLiveSync.getId()) { } else if (view.getId() == progressLiveSync.getId()) {
@ -690,8 +691,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
private void onPlaybackParameterChanged(final PlaybackParameters parameters) { private void onPlaybackParameterChanged(final PlaybackParameters parameters) {
if (parameters != null) { if (parameters != null) {
playbackSpeedButton.setText(formatSpeed(parameters.speed)); if (menu != null && player != null) {
playbackPitchButton.setText(formatPitch(parameters.pitch)); final MenuItem item = menu.findItem(R.id.action_playback_speed);
item.setTitle(formatSpeed(parameters.speed));
}
} }
} }

View file

@ -111,7 +111,7 @@
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<ImageButton <ImageButton
android:id="@+id/control_backward" android:id="@+id/control_fast_rewind"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@ -121,7 +121,7 @@
android:focusable="true" android:focusable="true"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:tint="?attr/colorAccent" android:tint="?attr/colorAccent"
android:src="@drawable/exo_controls_previous" android:src="@drawable/exo_controls_rewind"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
@ -161,7 +161,7 @@
android:visibility="invisible"/> android:visibility="invisible"/>
<ImageButton <ImageButton
android:id="@+id/control_forward" android:id="@+id/control_fast_forward"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_centerVertical="true" android:layout_centerVertical="true"
@ -172,7 +172,7 @@
android:focusable="true" android:focusable="true"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:tint="?attr/colorAccent" android:tint="?attr/colorAccent"
android:src="@drawable/exo_controls_next" android:src="@drawable/exo_controls_fastforward"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
</RelativeLayout> </RelativeLayout>
@ -185,8 +185,8 @@
android:orientation="horizontal" android:orientation="horizontal"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<TextView <ImageButton
android:id="@+id/control_playback_speed" android:id="@+id/control_backward"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="35dp" android:layout_height="35dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
@ -195,11 +195,13 @@
android:layout_toLeftOf="@+id/control_repeat" android:layout_toLeftOf="@+id/control_repeat"
android:gravity="center" android:gravity="center"
android:minWidth="50dp" android:minWidth="50dp"
android:text="1x" android:background="?attr/selectableItemBackgroundBorderless"
android:textColor="?attr/colorAccent" android:clickable="true"
android:textStyle="bold" android:focusable="true"
android:background="?attr/selectableItemBackground" android:scaleType="fitXY"
tools:ignore="HardcodedText,RtlHardcoded"/> android:src="@drawable/exo_controls_previous"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
<ImageButton <ImageButton
android:id="@+id/control_repeat" android:id="@+id/control_repeat"
@ -236,8 +238,8 @@
app:srcCompat="@drawable/ic_shuffle_white_24dp" app:srcCompat="@drawable/ic_shuffle_white_24dp"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
<TextView <ImageButton
android:id="@+id/control_playback_pitch" android:id="@+id/control_forward"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="35dp" android:layout_height="35dp"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
@ -246,11 +248,13 @@
android:layout_toRightOf="@+id/control_shuffle" android:layout_toRightOf="@+id/control_shuffle"
android:gravity="center" android:gravity="center"
android:minWidth="50dp" android:minWidth="50dp"
android:text="100%" android:background="?attr/selectableItemBackgroundBorderless"
android:textColor="?attr/colorAccent" android:clickable="true"
android:textStyle="bold" android:focusable="true"
android:background="?attr/selectableItemBackground" android:scaleType="fitXY"
tools:ignore="HardcodedText,RtlHardcoded"/> android:src="@drawable/exo_controls_next"
android:tint="?attr/colorAccent"
tools:ignore="ContentDescription" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -169,22 +169,6 @@
android:orientation="horizontal" android:orientation="horizontal"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<TextView
android:id="@+id/control_playback_speed"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/control_repeat"
android:gravity="center"
android:minWidth="50dp"
android:text="1x"
android:textColor="?attr/colorAccent"
android:textStyle="bold"
android:background="?attr/selectableItemBackground"
tools:ignore="HardcodedText,RtlHardcoded"/>
<ImageButton <ImageButton
android:id="@+id/control_repeat" android:id="@+id/control_repeat"
android:layout_width="30dp" android:layout_width="30dp"
@ -207,7 +191,7 @@
android:layout_height="40dp" android:layout_height="40dp"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_toLeftOf="@+id/control_play_pause" android:layout_toLeftOf="@+id/control_fast_rewind"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
@ -216,6 +200,20 @@
android:src="@drawable/exo_controls_previous" android:src="@drawable/exo_controls_previous"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
<ImageButton
android:id="@+id/control_fast_rewind"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@id/control_play_pause"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:scaleType="fitCenter"
android:tint="?attr/colorAccent"
android:src="@drawable/exo_controls_rewind"/>
<ImageButton <ImageButton
android:id="@+id/control_play_pause" android:id="@+id/control_play_pause"
android:layout_width="50dp" android:layout_width="50dp"
@ -251,13 +249,28 @@
android:visibility="invisible" android:visibility="invisible"
tools:visibility="visible"/> tools:visibility="visible"/>
<ImageButton
android:id="@+id/control_fast_forward"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_toRightOf="@id/control_play_pause"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:scaleType="fitCenter"
android:tint="?attr/colorAccent"
android:src="@drawable/exo_controls_fastforward"/>
<ImageButton <ImageButton
android:id="@+id/control_forward" android:id="@+id/control_forward"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginRight="5dp" android:layout_marginRight="5dp"
android:layout_toRightOf="@+id/control_play_pause" android:layout_toRightOf="@+id/control_fast_forward"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
@ -282,21 +295,6 @@
app:srcCompat="@drawable/ic_shuffle_white_24dp" app:srcCompat="@drawable/ic_shuffle_white_24dp"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
<TextView
android:id="@+id/control_playback_pitch"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/control_shuffle"
android:gravity="center"
android:minWidth="50dp"
android:text="100%"
android:textColor="?attr/colorAccent"
android:textStyle="bold"
android:background="?attr/selectableItemBackground"
tools:ignore="HardcodedText,RtlHardcoded"/>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -10,6 +10,14 @@
android:visible="true" android:visible="true"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_playback_speed"
android:title="1x"
android:tooltipText="@string/playback_speed_control"
android:visible="true"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_mute" android:id="@+id/action_mute"
android:icon="?attr/ic_volume_off" android:icon="?attr/ic_volume_off"