Browse Source

Media player fixes: better handling of RTL & orientation

cryfs
Hardcore Sushi 2 months ago
parent
commit
5144947a4a
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
  1. 17
      app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt
  2. 23
      app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt
  3. 1
      app/src/main/res/layout/audio_exo_styled_player_control_view.xml
  4. 1
      app/src/main/res/layout/exo_center_controls.xml

17
app/src/main/java/sushi/hardcore/droidfs/file_viewers/VideoPlayer.kt

@ -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) {

23
app/src/main/java/sushi/hardcore/droidfs/widgets/DoubleTapPlayerView.kt

@ -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)
}
}

1
app/src/main/res/layout/audio_exo_styled_player_control_view.xml

@ -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">

1
app/src/main/res/layout/exo_center_controls.xml

@ -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">

Loading…
Cancel
Save