From 72321b8ec54cc85d6e71e60fca1a968aad1c46b7 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Wed, 23 Mar 2022 14:56:15 +0100 Subject: [PATCH] Switch to StyledPlayerView --- app/build.gradle | 2 +- .../droidfs/file_viewers/MediaPlayer.kt | 2 +- .../droidfs/widgets/DoubleTapPlayerView.kt | 56 ++++++- .../main/res/layout/activity_audio_player.xml | 5 +- .../main/res/layout/activity_video_player.xml | 1 + .../audio_exo_styled_player_control_view.xml | 122 ++++++++++++++ .../main/res/layout/exo_center_controls.xml | 28 ++++ .../res/layout/exo_player_control_view.xml | 73 --------- .../layout/exo_styled_player_control_view.xml | 149 ++++++++++++++++++ app/src/main/res/values/colors.xml | 3 +- 10 files changed, 361 insertions(+), 80 deletions(-) create mode 100644 app/src/main/res/layout/audio_exo_styled_player_control_view.xml create mode 100644 app/src/main/res/layout/exo_center_controls.xml delete mode 100644 app/src/main/res/layout/exo_player_control_view.xml create mode 100644 app/src/main/res/layout/exo_styled_player_control_view.xml diff --git a/app/build.gradle b/app/build.gradle index 0c6b9a7..d08d589 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,7 +70,7 @@ dependencies { implementation "com.github.bumptech.glide:glide:4.12.0" implementation "androidx.biometric:biometric-ktx:1.2.0-alpha04" - def exoplayer_version = "2.17.0" + def exoplayer_version = "2.17.1" implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version" implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version" diff --git a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt index f37ffa1..c4f1239 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/file_viewers/MediaPlayer.kt @@ -31,7 +31,7 @@ abstract class MediaPlayer: FileViewerActivity() { } private fun initializePlayer(){ - player = ExoPlayer.Builder(this).build() + player = ExoPlayer.Builder(this).setSeekForwardIncrementMs(5000).build() bindPlayer(player) createPlaylist() for (e in mappedPlaylist) { diff --git a/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt b/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt index ad9d2f2..921d3ac 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt @@ -2,20 +2,29 @@ package sushi.hardcore.droidfs.widgets import android.annotation.SuppressLint import android.content.Context +import android.content.res.Configuration import android.media.session.PlaybackState import android.os.Handler import android.os.Looper import android.util.AttributeSet import android.view.GestureDetector import android.view.MotionEvent +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.FrameLayout +import android.widget.LinearLayout import androidx.core.view.GestureDetectorCompat -import com.google.android.exoplayer2.ui.PlayerView +import androidx.core.view.updateLayoutParams +import androidx.core.view.updatePadding +import com.google.android.exoplayer2.ui.StyledPlayerView +import sushi.hardcore.droidfs.R class DoubleTapPlayerView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -): PlayerView(context, attrs, defStyleAttr) { +) : StyledPlayerView(context, attrs, defStyleAttr) { companion object { const val SEEK_SECONDS = 10 @@ -67,6 +76,21 @@ class DoubleTapPlayerView @JvmOverloads constructor( } } private val gestureDetector = GestureDetectorCompat(context, gestureListener) + private val density by lazy { + context.resources.displayMetrics.density + } + private val originalExoIconPaddingBottom by lazy { + resources.getDimension(R.dimen.exo_icon_padding_bottom) + } + private val originalExoIconSize by lazy { + resources.getDimension(R.dimen.exo_icon_size) + } + + init { + if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { + updateButtonSize(Configuration.ORIENTATION_LANDSCAPE) + } + } @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { @@ -111,4 +135,32 @@ class DoubleTapPlayerView @JvmOverloads constructor( } } } + + private fun updateButtonSize(orientation: Int) { + val size = (if (orientation == Configuration.ORIENTATION_LANDSCAPE) 45*density else originalExoIconSize).toInt() + listOf(R.id.exo_prev, R.id.exo_rew_with_amount, R.id.exo_play_pause, R.id.exo_ffwd_with_amount, R.id.exo_next).forEach { + findViewById(it).updateLayoutParams { + width = size + height = size + } + } + // fix text vertical alignment inside icons + val paddingBottom = (if (orientation == Configuration.ORIENTATION_LANDSCAPE) 15*density else originalExoIconPaddingBottom).toInt() + listOf(R.id.exo_rew_with_amount, R.id.exo_ffwd_with_amount).forEach { + findViewById