Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add speedup & down to sound player UI #1530

Merged
merged 10 commits into from Jan 6, 2024
Expand Up @@ -398,7 +398,12 @@ class AudioService : Service(), OnCompletionListener, OnPreparedListener,
processStopRequest()
} else if (ACTION_REWIND == action) {
processRewindRequest()
} else if (ACTION_UPDATE_REPEAT == action) {
}else if (ACTION_SPEED_DOWN == action){
processSpeedDownPlayback()
}else if (ACTION_SPEED_UP == action){
processSpeedUpPlayback()
}
else if (ACTION_UPDATE_REPEAT == action) {
val playInfo = intent.getParcelableExtra<AudioRequest>(EXTRA_PLAY_INFO)
val localAudioQueue = audioQueue
if (playInfo != null && localAudioQueue != null) {
Expand Down Expand Up @@ -677,7 +682,43 @@ class AudioService : Service(), OnCompletionListener, OnPreparedListener,
}
}
}
private fun processSpeedUpPlayback() {
if (State.Playing === state) {
speedUpPlayback()
}
}

private fun processSpeedDownPlayback() {
if (State.Playing === state) {
speedDownPlayback()
}
}

private fun speedUpPlayback() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
player?.playbackParams?.let { params ->
val newSpeed = params.speed + 0.15f
// todo should be handled based on Qari type
if (newSpeed <= 1.5){
params.setSpeed(newSpeed)
player?.playbackParams = params
}
}
}
}

private fun speedDownPlayback() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
player?.playbackParams?.let { params ->
val newSpeed = params.speed - 0.1f
// todo should be handled based on Qari type
if (newSpeed >= 0.5){
params.setSpeed(newSpeed)
player?.playbackParams = params
}
}
}
}
private fun processSkipRequest() {
if (audioRequest == null) {
return
Expand Down Expand Up @@ -1361,6 +1402,8 @@ class AudioService : Service(), OnCompletionListener, OnPreparedListener,
const val ACTION_STOP = "com.quran.labs.androidquran.action.STOP"
const val ACTION_SKIP = "com.quran.labs.androidquran.action.SKIP"
const val ACTION_REWIND = "com.quran.labs.androidquran.action.REWIND"
const val ACTION_SPEED_UP = "com.quran.labs.androidquran.action.SPEED_UP"
const val ACTION_SPEED_DOWN = "com.quran.labs.androidquran.action.SPEED_DOWN"
const val ACTION_CONNECT = "com.quran.labs.androidquran.action.CONNECT"
const val ACTION_UPDATE_REPEAT = "com.quran.labs.androidquran.action.UPDATE_REPEAT"

Expand Down
Expand Up @@ -1583,6 +1583,18 @@ public void onPausePressed() {
audioStatusBar.switchMode(AudioStatusBar.PAUSED_MODE);
}

@Override
public void onUpPressed() {
startService(audioUtils.getAudioIntent(this,
AudioService.ACTION_SPEED_UP));
}

@Override
public void onDownPressed() {
startService(audioUtils.getAudioIntent(this,
AudioService.ACTION_SPEED_DOWN));
}

@Override
public void onNextPressed() {
startService(audioUtils.getAudioIntent(this,
Expand Down
Expand Up @@ -74,6 +74,8 @@ public interface AudioBarListener {
void onNextPressed();
void onPreviousPressed();
void onStopPressed();
void onDownPressed();
void onUpPressed();
void onCancelPressed(boolean stopDownload);
void setRepeatCount(int repeatCount);
void onAcceptPressed();
Expand Down Expand Up @@ -460,6 +462,8 @@ private void showPlayingMode(boolean isPaused) {
addButton(R.drawable.ic_previous, withWeight);
addButton(button, withWeight);
addButton(R.drawable.ic_next, withWeight);
addButton(R.drawable.ic_neg_1_24, withWeight);
addButton(R.drawable.ic_plus_1_24, withWeight);

addButton(repeatButton, R.drawable.ic_repeat, withWeight);
updateRepeatButtonText();
Expand Down Expand Up @@ -571,6 +575,10 @@ public void onClick(View view) {
}
} else if (tag == R.drawable.ic_next) {
audioBarListener.onNextPressed();
} else if (tag == R.drawable.ic_neg_1_24) {
audioBarListener.onDownPressed();
} else if (tag == R.drawable.ic_plus_1_24) {
audioBarListener.onUpPressed();
} else if (tag == R.drawable.ic_previous) {
audioBarListener.onPreviousPressed();
} else if (tag == R.drawable.ic_repeat) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_neg_1_24.xml
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M4,11v2h8v-2L4,11zM19,18h-2L17,7.38L14,8.4L14,6.7L18.7,5h0.3v13z" />
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_plus_1_24.xml
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M10,7L8,7v4L4,11v2h4v4h2v-4h4v-2h-4L10,7zM20,18h-2L18,7.38L15,8.4L15,6.7L19.7,5h0.3v13z" />
</vector>