add continous playback speed slider

This commit is contained in:
Bnyro 2022-08-25 22:48:12 +02:00
parent 1e5bd4d6fc
commit 207fe64b58
2 changed files with 25 additions and 8 deletions

View File

@ -43,6 +43,7 @@ import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.api.CronetHelper import com.github.libretube.api.CronetHelper
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.databinding.DialogPlaybackSpeedBinding
import com.github.libretube.databinding.DoubleTapOverlayBinding import com.github.libretube.databinding.DoubleTapOverlayBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.databinding.FragmentPlayerBinding import com.github.libretube.databinding.FragmentPlayerBinding
@ -509,17 +510,17 @@ class PlayerFragment : BaseFragment() {
} }
override fun onPlaybackSpeedClicked() { override fun onPlaybackSpeedClicked() {
val playbackSpeeds = context?.resources?.getStringArray(R.array.playbackSpeed)!! val playbackSpeedBinding = DialogPlaybackSpeedBinding.inflate(layoutInflater)
val playbackSpeedValues = playbackSpeedBinding.slider.value = exoPlayer.playbackParameters.speed
context?.resources?.getStringArray(R.array.playbackSpeedValues)!!
// change playback speed dialog // change playback speed dialog
MaterialAlertDialogBuilder(requireContext()) MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.change_playback_speed) .setTitle(R.string.change_playback_speed)
.setItems(playbackSpeeds) { _, index -> .setView(playbackSpeedBinding.root)
// set the new playback speed .setNegativeButton(R.string.cancel, null)
val newPlaybackSpeed = playbackSpeedValues[index].toFloat() .setPositiveButton(R.string.okay) { _, _ ->
exoPlayer.setPlaybackSpeed(newPlaybackSpeed) exoPlayer.setPlaybackSpeed(
playbackSpeedBinding.slider.value
)
} }
.show() .show()
} }

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
android:value="1"
android:valueFrom="0.25"
android:valueTo="5" />
</LinearLayout>