From 85ba04553963cfb07d14bcfaa92aabc2da1b5d86 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Sat, 26 Aug 2023 19:52:16 +0200 Subject: [PATCH] feat(player): play music at 1x speed (#4634) Co-authored-by: Bnyro <82752168+Bnyro@users.noreply.github.com> --- app/src/main/java/com/github/libretube/api/obj/Streams.kt | 4 ++++ .../java/com/github/libretube/helpers/PreferenceHelper.kt | 1 - .../com/github/libretube/ui/fragments/PlayerFragment.kt | 8 +++++++- .../java/com/github/libretube/ui/sheets/StatsSheet.kt | 1 - 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/Streams.kt b/app/src/main/java/com/github/libretube/api/obj/Streams.kt index 136d14ce3c..2b5ae093fc 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Streams.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Streams.kt @@ -91,4 +91,8 @@ data class Streams( shortDescription = description ) } + + companion object { + const val categoryMusic = "Music" + } } diff --git a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt index 439e5eaa58..5f9fdea4f2 100644 --- a/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt @@ -6,7 +6,6 @@ import androidx.core.content.edit import androidx.preference.PreferenceManager import com.github.libretube.constants.PreferenceKeys import java.time.Instant -import java.util.UUID object PreferenceHelper { /** diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index d11ed3c81c..e7233555e9 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -101,7 +101,6 @@ import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog -import com.github.libretube.ui.sheets.StatsSheet import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.interfaces.OnlinePlayerOptions import com.github.libretube.ui.listeners.SeekbarPreviewListener @@ -111,6 +110,7 @@ import com.github.libretube.ui.sheets.BaseBottomSheet import com.github.libretube.ui.sheets.ChaptersBottomSheet import com.github.libretube.ui.sheets.CommentsSheet import com.github.libretube.ui.sheets.PlayingQueueSheet +import com.github.libretube.ui.sheets.StatsSheet import com.github.libretube.util.HtmlParser import com.github.libretube.util.LinkHandler import com.github.libretube.util.NowPlayingNotification @@ -938,6 +938,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { override fun onPlaybackStateChanged(playbackState: Int) { saveWatchPosition() + if (playbackState == Player.STATE_READY) { + if (streams.category == Streams.categoryMusic) { + exoPlayer.setPlaybackSpeed(1f) + } + } + // set the playback speed to one if having reached the end of a livestream if (playbackState == Player.STATE_BUFFERING && binding.player.isLive && exoPlayer.duration - exoPlayer.currentPosition < 700 diff --git a/app/src/main/java/com/github/libretube/ui/sheets/StatsSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/StatsSheet.kt index 877c9ca2ad..7a7ff14a46 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/StatsSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/StatsSheet.kt @@ -7,7 +7,6 @@ import android.view.View import android.view.ViewGroup import androidx.media3.exoplayer.ExoPlayer import com.github.libretube.databinding.DialogStatsBinding -import com.github.libretube.ui.sheets.ExpandedBottomSheet import com.github.libretube.util.TextUtils class StatsSheet(