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

View File

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

View File

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

View File

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