playback speed bottom sheet

This commit is contained in:
Bnyro 2022-10-01 11:43:40 +02:00
parent d57ec17662
commit 57b266aeb7
14 changed files with 130 additions and 41 deletions

View File

@ -10,7 +10,7 @@ import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setWatchProgressLength import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.ChannelViewHolder import com.github.libretube.ui.viewholders.ChannelViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper

View File

@ -13,7 +13,7 @@ import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.setFormattedDuration import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistViewHolder import com.github.libretube.ui.viewholders.PlaylistViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper

View File

@ -10,7 +10,7 @@ import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.databinding.PlaylistsRowBinding import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.sheets.PlaylistOptionsBottomSheet import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistsViewHolder import com.github.libretube.ui.viewholders.PlaylistsViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper

View File

@ -16,8 +16,8 @@ import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setFormattedDuration import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.sheets.PlaylistOptionsBottomSheet import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SearchViewHolder import com.github.libretube.ui.viewholders.SearchViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper

View File

@ -11,7 +11,7 @@ import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setFormattedDuration import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SubscriptionViewHolder import com.github.libretube.ui.viewholders.SubscriptionViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper

View File

@ -9,7 +9,7 @@ import com.github.libretube.db.DatabaseHelper
import com.github.libretube.db.obj.WatchHistoryItem import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.extensions.setFormattedDuration import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.extensions.setWatchProgressLength import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.WatchHistoryViewHolder import com.github.libretube.ui.viewholders.WatchHistoryViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper

View File

@ -152,7 +152,6 @@ class PlayerFragment : BaseFragment() {
private var token = "" private var token = ""
private var relatedStreamsEnabled = true private var relatedStreamsEnabled = true
private var autoRotationEnabled = true private var autoRotationEnabled = true
private var playbackSpeed = "1F"
private var pausePlayerOnScreenOffEnabled = false private var pausePlayerOnScreenOffEnabled = false
private var fullscreenOrientationPref = "ratio" private var fullscreenOrientationPref = "ratio"
private var watchHistoryEnabled = true private var watchHistoryEnabled = true
@ -256,11 +255,6 @@ class PlayerFragment : BaseFragment() {
true true
) )
playbackSpeed = PreferenceHelper.getString(
PreferenceKeys.PLAYBACK_SPEED,
"1"
).replace("F", "") // due to old way to handle it (with float)
fullscreenOrientationPref = PreferenceHelper.getString( fullscreenOrientationPref = PreferenceHelper.getString(
PreferenceKeys.FULLSCREEN_ORIENTATION, PreferenceKeys.FULLSCREEN_ORIENTATION,
"ratio" "ratio"
@ -542,9 +536,6 @@ class PlayerFragment : BaseFragment() {
} }
} }
// set default playback speed
exoPlayer.setPlaybackSpeed(playbackSpeed.toFloat())
// share button // share button
binding.relPlayerShare.setOnClickListener { binding.relPlayerShare.setOnClickListener {
val shareDialog = ShareDialog(videoId!!, false, exoPlayer.currentPosition / 1000) val shareDialog = ShareDialog(videoId!!, false, exoPlayer.currentPosition / 1000)

View File

@ -15,9 +15,9 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.FragmentPlaylistBinding import com.github.libretube.databinding.FragmentPlaylistBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.adapters.PlaylistAdapter import com.github.libretube.ui.adapters.PlaylistAdapter
import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.base.BaseFragment
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException import java.io.IOException

View File

@ -0,0 +1,35 @@
package com.github.libretube.ui.sheets
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.github.libretube.databinding.PlaybackBottomSheetBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
class PlaybackSpeedSheet(
private val onChange: (speed: Float, pitch: Float) -> Unit
) : BottomSheetDialogFragment() {
private lateinit var binding: PlaybackBottomSheetBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = PlaybackBottomSheetBinding.inflate(layoutInflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.speed.addOnChangeListener { _, value, _ ->
onChange.invoke(value, binding.pitch.value)
}
binding.pitch.addOnChangeListener { _, value, _ ->
onChange.invoke(binding.speed.value, value)
}
}
}

View File

@ -1,4 +1,4 @@
package com.github.libretube.sheets package com.github.libretube.ui.sheets
import android.os.Bundle import android.os.Bundle
import android.text.InputType import android.text.InputType

View File

@ -1,4 +1,4 @@
package com.github.libretube.sheets package com.github.libretube.ui.sheets
import android.os.Bundle import android.os.Bundle
import android.widget.Toast import android.widget.Toast

View File

@ -5,21 +5,21 @@ import android.content.Context
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.databinding.DialogSliderBinding
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.models.interfaces.DoubleTapInterface import com.github.libretube.models.interfaces.DoubleTapInterface
import com.github.libretube.models.interfaces.PlayerOptionsInterface import com.github.libretube.models.interfaces.PlayerOptionsInterface
import com.github.libretube.obj.BottomSheetItem import com.github.libretube.obj.BottomSheetItem
import com.github.libretube.ui.activities.MainActivity import com.github.libretube.ui.activities.MainActivity
import com.github.libretube.ui.sheets.PlaybackSpeedSheet
import com.github.libretube.util.DoubleTapListener import com.github.libretube.util.DoubleTapListener
import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.PreferenceHelper
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.trackselection.TrackSelector import com.google.android.exoplayer2.trackselection.TrackSelector
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
import com.google.android.exoplayer2.ui.StyledPlayerView import com.google.android.exoplayer2.ui.StyledPlayerView
@ -58,6 +58,11 @@ internal class CustomExoPlayerView(
true true
) )
val playbackSpeed = PreferenceHelper.getString(
PreferenceKeys.PLAYBACK_SPEED,
"1"
).replace("F", "")
private val seekIncrement = PreferenceHelper.getString( private val seekIncrement = PreferenceHelper.getString(
PreferenceKeys.SEEK_INCREMENT, PreferenceKeys.SEEK_INCREMENT,
"10.0" "10.0"
@ -102,6 +107,11 @@ internal class CustomExoPlayerView(
initializeAdvancedOptions(context) initializeAdvancedOptions(context)
player?.playbackParameters = PlaybackParameters(
playbackSpeed.toFloat(),
1.0f
)
// locking the player // locking the player
binding.lockPlayer.setOnClickListener { binding.lockPlayer.setOnClickListener {
// change the locked/unlocked icon // change the locked/unlocked icon
@ -332,26 +342,12 @@ internal class CustomExoPlayerView(
} }
fun onPlaybackSpeedClicked() { fun onPlaybackSpeedClicked() {
val playbackSpeedBinding = DialogSliderBinding.inflate( PlaybackSpeedSheet { speed, pitch ->
LayoutInflater.from(context) player?.playbackParameters = PlaybackParameters(
) speed,
playbackSpeedBinding.slider.apply { pitch
valueFrom = 0.25f )
valueTo = 4.0f }.show(childFragmentManager, null)
stepSize = 0.25f
value = player?.playbackParameters?.speed ?: 1f
}
// change playback speed dialog
MaterialAlertDialogBuilder(context)
.setTitle(R.string.change_playback_speed)
.setView(playbackSpeedBinding.root)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.okay) { _, _ ->
player?.setPlaybackSpeed(
playbackSpeedBinding.slider.value
)
}
.show()
} }
fun onResizeModeClicked() { fun onResizeModeClicked() {

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/standard_bottom_sheet"
style="@style/Widget.Material3.BottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Drag handle for accessibility -->
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
android:id="@+id/drag_handle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/playback_speed" />
<com.google.android.material.slider.Slider
android:id="@+id/speed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stepSize="0.25"
android:value="1.0"
android:valueFrom="0.25"
android:valueTo="4.0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/playback_pitch" />
<com.google.android.material.slider.Slider
android:id="@+id/pitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stepSize="0.25"
android:value="1.0"
android:valueFrom="0.5"
android:valueTo="2.0" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -337,6 +337,7 @@
<string name="progressive_load_interval">Progressive load interval size</string> <string name="progressive_load_interval">Progressive load interval size</string>
<string name="progressive_load_interval_summary">A lower value may speed up initial video loading.</string> <string name="progressive_load_interval_summary">A lower value may speed up initial video loading.</string>
<string name="default_load_interval">Default</string> <string name="default_load_interval">Default</string>
<string name="playback_pitch">Pitch</string>
<!-- Notification channel strings --> <!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string> <string name="download_channel_name">Download Service</string>