Media player fixes: better handling of RTL & orientation

This commit is contained in:
Matéo Duparc 2022-05-07 14:51:20 +02:00
parent 6b52eed9d0
commit 5144947a4a
Signed by untrusted user: hardcoresushi
GPG Key ID: AFE384344A45E13A
4 changed files with 24 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package sushi.hardcore.droidfs.file_viewers
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import com.google.android.exoplayer2.ExoPlayer
import sushi.hardcore.droidfs.databinding.ActivityVideoPlayerBinding
@ -14,23 +15,23 @@ class VideoPlayer: MediaPlayer() {
override fun viewFile() {
binding = ActivityVideoPlayerBinding.inflate(layoutInflater)
setContentView(binding.root)
super.viewFile()
}
override fun bindPlayer(player: ExoPlayer) {
binding.videoPlayer.player = player
binding.videoPlayer.doubleTapOverlay = binding.doubleTapOverlay
binding.videoPlayer.setControllerVisibilityListener { visibility ->
binding.topBar.visibility = visibility
}
binding.rotateButton.setOnClickListener {
requestedOrientation =
if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE)
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
else
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
} else {
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
}
}
super.viewFile()
}
override fun bindPlayer(player: ExoPlayer) {
binding.videoPlayer.player = player
}
override fun onNewFileName(fileName: String) {

View File

@ -88,7 +88,7 @@ class DoubleTapPlayerView @JvmOverloads constructor(
init {
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
updateButtonSize(Configuration.ORIENTATION_LANDSCAPE)
handleOrientationChange(Configuration.ORIENTATION_LANDSCAPE)
}
}
@ -151,16 +151,19 @@ class DoubleTapPlayerView @JvmOverloads constructor(
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
private fun handleOrientationChange(orientation: Int) {
val centerControls = findViewById<LinearLayout>(R.id.exo_center_controls)
(centerControls.parent as ViewGroup).removeView(centerControls)
findViewById<FrameLayout>(
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
R.id.center_controls_bar
else
R.id.center_controls_external
).addView(centerControls)
updateButtonSize(newConfig.orientation)
findViewById<FrameLayout>(if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
R.id.center_controls_bar
} else {
R.id.center_controls_external
}).addView(centerControls)
updateButtonSize(orientation)
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
handleOrientationChange(newConfig.orientation)
}
}

View File

@ -26,6 +26,7 @@
android:layout_gravity="center_horizontal"
android:background="@android:color/transparent"
android:gravity="center"
android:layoutDirection="ltr"
android:padding="@dimen/exo_styled_controls_padding"
android:layout_marginBottom="-40dp"
android:clipToPadding="false">

View File

@ -8,6 +8,7 @@
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:layoutDirection="ltr"
android:padding="@dimen/exo_styled_controls_padding"
android:clipToPadding="false">