mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #4367 from Bnyro/master
feat: forward and rewind controls for audio player
This commit is contained in:
commit
dd7267f7b6
10
app/src/main/java/com/github/libretube/extensions/SeekBy.kt
Normal file
10
app/src/main/java/com/github/libretube/extensions/SeekBy.kt
Normal file
@ -0,0 +1,10 @@
|
||||
package com.github.libretube.extensions
|
||||
|
||||
import androidx.media3.common.Player
|
||||
|
||||
/**
|
||||
* Forward or rewind by the provided [timeDiff] in milliseconds
|
||||
*/
|
||||
fun Player.seekBy(timeDiff: Long) {
|
||||
seekTo(currentPosition + timeDiff)
|
||||
}
|
@ -26,6 +26,7 @@ import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.databinding.FragmentAudioPlayerBinding
|
||||
import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.normalize
|
||||
import com.github.libretube.extensions.seekBy
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.helpers.AudioHelper
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
@ -129,6 +130,16 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
PlayingQueue.onQueueItemSelected(currentIndex + 1)
|
||||
}
|
||||
|
||||
listOf(binding.forwardTV, binding.rewindTV).forEach {
|
||||
it.text = (PlayerHelper.seekIncrement / 1000).toString()
|
||||
}
|
||||
binding.rewindFL.setOnClickListener {
|
||||
playerService?.player?.seekBy(-PlayerHelper.seekIncrement)
|
||||
}
|
||||
binding.forwardFL.setOnClickListener {
|
||||
playerService?.player?.seekBy(PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
binding.openQueue.setOnClickListener {
|
||||
PlayingQueueSheet().show(childFragmentManager)
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ import com.github.libretube.enums.ShareObjectType
|
||||
import com.github.libretube.extensions.formatShort
|
||||
import com.github.libretube.extensions.hideKeyboard
|
||||
import com.github.libretube.extensions.parcelable
|
||||
import com.github.libretube.extensions.seekBy
|
||||
import com.github.libretube.extensions.setMetadata
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toastFromMainDispatcher
|
||||
@ -214,11 +215,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
PlayerEvent.Forward -> {
|
||||
exoPlayer.seekTo(exoPlayer.currentPosition + PlayerHelper.seekIncrement)
|
||||
exoPlayer.seekBy(PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
PlayerEvent.Rewind -> {
|
||||
exoPlayer.seekTo(exoPlayer.currentPosition - PlayerHelper.seekIncrement)
|
||||
exoPlayer.seekBy(-PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
PlayerEvent.Next -> {
|
||||
|
@ -40,6 +40,7 @@ import com.github.libretube.databinding.PlayerGestureControlsViewBinding
|
||||
import com.github.libretube.extensions.dpToPx
|
||||
import com.github.libretube.extensions.normalize
|
||||
import com.github.libretube.extensions.round
|
||||
import com.github.libretube.extensions.seekBy
|
||||
import com.github.libretube.helpers.AudioHelper
|
||||
import com.github.libretube.helpers.BrightnessHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
@ -267,10 +268,10 @@ open class CustomExoPlayerView(
|
||||
it?.text = seekIncrementText
|
||||
}
|
||||
binding.forwardBTN.setOnClickListener {
|
||||
player?.seekTo(player!!.currentPosition + PlayerHelper.seekIncrement)
|
||||
player?.seekBy(PlayerHelper.seekIncrement)
|
||||
}
|
||||
binding.rewindBTN.setOnClickListener {
|
||||
player?.seekTo(player!!.currentPosition - PlayerHelper.seekIncrement)
|
||||
player?.seekBy(-PlayerHelper.seekIncrement)
|
||||
}
|
||||
if (PlayerHelper.doubleTapToSeek) return
|
||||
|
||||
@ -363,7 +364,7 @@ open class CustomExoPlayerView(
|
||||
}
|
||||
|
||||
private fun rewind() {
|
||||
player?.seekTo((player?.currentPosition ?: 0L) - PlayerHelper.seekIncrement)
|
||||
player?.seekBy(-PlayerHelper.seekIncrement)
|
||||
|
||||
// show the rewind button
|
||||
doubleTapOverlayBinding?.apply {
|
||||
@ -378,7 +379,7 @@ open class CustomExoPlayerView(
|
||||
}
|
||||
|
||||
private fun forward() {
|
||||
player?.seekTo(player!!.currentPosition + PlayerHelper.seekIncrement)
|
||||
player?.seekBy(PlayerHelper.seekIncrement)
|
||||
|
||||
// show the forward button
|
||||
doubleTapOverlayBinding?.apply {
|
||||
|
@ -30,6 +30,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
||||
import com.github.libretube.extensions.seekBy
|
||||
import com.github.libretube.helpers.BackgroundHelper
|
||||
import com.github.libretube.helpers.ImageHelper
|
||||
import com.github.libretube.helpers.PlayerHelper
|
||||
@ -251,11 +252,11 @@ class NowPlayingNotification(
|
||||
}
|
||||
|
||||
REWIND -> {
|
||||
player.seekTo(player.currentPosition - PlayerHelper.seekIncrement)
|
||||
player.seekBy(-PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
FORWARD -> {
|
||||
player.seekTo(player.currentPosition + PlayerHelper.seekIncrement)
|
||||
player.seekBy(PlayerHelper.seekIncrement)
|
||||
}
|
||||
|
||||
PLAY_PAUSE -> {
|
||||
|
@ -186,6 +186,31 @@
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="36dp">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/rewindFL"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="?attr/selectableItemBackgroundBorderless">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_rewind_md" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rewindTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textSize="8sp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="SmallSp" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/prev"
|
||||
android:layout_width="48dp"
|
||||
@ -213,9 +238,33 @@
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_next" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/forwardFL"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="?attr/selectableItemBackgroundBorderless">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_forward_md" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/forwardTV"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textSize="8sp"
|
||||
android:textStyle="bold"
|
||||
tools:ignore="SmallSp" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
|
Loading…
Reference in New Issue
Block a user