Skip to content

Commit

Permalink
feat: Added buttons for backward and forward steps to audio player
Browse files Browse the repository at this point in the history
Co-authored-by: 23rd <[email protected]>
  • Loading branch information
omg-xtao and 23rd committed Jan 9, 2024
1 parent e08adc2 commit b4080a0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,12 @@ public boolean seekToProgress(MessageObject messageObject, float progress) {
return true;
}

public void seekShift(int ms) {
if (audioPlayer != null) {
audioPlayer.seekTo(Math.max(0, audioPlayer.getCurrentPosition() + ms));
}
}

public long getDuration() {
if (audioPlayer == null) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@

public class AudioPlayerAlert extends BottomSheet implements NotificationCenter.NotificationCenterDelegate, DownloadController.FileDownloadProgressListener {

private TextView forwardButton;
private TextView backwardButton;

private ActionBar actionBar;
private View actionBarShadow;
private View playerShadow;
Expand Down Expand Up @@ -747,14 +750,52 @@ public CharSequence getContentDescription() {
FrameLayout bottomView = new FrameLayout(context) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int dist = ((right - left) - AndroidUtilities.dp(8 + 48 * 5)) / 4;
for (int a = 0; a < 5; a++) {
int dist = ((right - left) - AndroidUtilities.dp(8 + 48 * 7)) / 4;
int forkButtonsLayouted = 0;
for (int a = 0; a < 7; a++) {
int l = AndroidUtilities.dp(4 + 48 * a) + dist * a;
int t = AndroidUtilities.dp(9);
buttons[a].layout(l, t, l + buttons[a].getMeasuredWidth(), t + buttons[a].getMeasuredHeight());
if (a == 1) {
backwardButton.layout(l, t, l + backwardButton.getMeasuredWidth(), t + backwardButton.getMeasuredHeight());
forkButtonsLayouted++;
} else if (a == 5) {
forwardButton.layout(l, t, l + forwardButton.getMeasuredWidth(), t + forwardButton.getMeasuredHeight());
forkButtonsLayouted++;
} else {
int i = a - forkButtonsLayouted;
buttons[i].layout(l, t, l + buttons[i].getMeasuredWidth(), t + buttons[i].getMeasuredHeight());
}
}
}
};

{
final int s = 5;
final int color = getThemedColor(Theme.key_listSelector);
final FrameLayout.LayoutParams frame = LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP);
forwardButton = new TextView(context);
forwardButton.setText("+" + s + "s");
forwardButton.setGravity(Gravity.CENTER);
bottomView.addView(forwardButton, frame);

backwardButton = new TextView(context);
backwardButton.setText("–" + s + "s");
backwardButton.setGravity(Gravity.CENTER);
bottomView.addView(backwardButton, frame);

if (Build.VERSION.SDK_INT >= 21) {
forwardButton.setBackgroundDrawable(Theme.createSelectorDrawable(color, 1, AndroidUtilities.dp(24)));
backwardButton.setBackgroundDrawable(Theme.createSelectorDrawable(color, 1, AndroidUtilities.dp(24)));
}

forwardButton.setOnClickListener(view -> {
MediaController.getInstance().seekShift(s * 1000);
});
backwardButton.setOnClickListener(view -> {
MediaController.getInstance().seekShift(-s * 1000);
});
}

playerLayout.addView(bottomView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 66, Gravity.TOP | Gravity.LEFT, 0, 111, 0, 0));

buttons[0] = repeatButton = new ActionBarMenuItem(context, null, 0, 0, false, resourcesProvider);
Expand Down

0 comments on commit b4080a0

Please sign in to comment.