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

62 lines
2.1 KiB
Kotlin
Raw Normal View History

2020-07-17 16:35:39 +02:00
package sushi.hardcore.droidfs.file_viewers
2021-04-05 12:42:35 +02:00
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.view.View
2021-11-09 16:27:59 +01:00
import com.google.android.exoplayer2.ExoPlayer
2022-09-23 12:09:22 +02:00
import com.google.android.exoplayer2.ui.StyledPlayerView
2021-06-11 20:23:54 +02:00
import sushi.hardcore.droidfs.databinding.ActivityVideoPlayerBinding
2021-04-05 12:42:35 +02:00
class VideoPlayer: MediaPlayer() {
2021-04-05 12:42:35 +02:00
private var firstPlay = true
private val autoFit by lazy {
sharedPrefs.getBoolean("autoFit", false)
}
2021-06-11 20:23:54 +02:00
private lateinit var binding: ActivityVideoPlayerBinding
2020-07-17 16:35:39 +02:00
override fun viewFile() {
2021-06-11 20:23:54 +02:00
binding = ActivityVideoPlayerBinding.inflate(layoutInflater)
setContentView(binding.root)
applyNavigationBarMargin(binding.root)
2022-01-18 20:18:44 +01:00
binding.videoPlayer.doubleTapOverlay = binding.doubleTapOverlay
2022-09-23 12:09:22 +02:00
binding.videoPlayer.setControllerVisibilityListener(StyledPlayerView.ControllerVisibilityListener { visibility ->
2022-03-05 19:23:48 +01:00
binding.topBar.visibility = visibility
if (visibility == View.VISIBLE) {
showPartialSystemUi()
} else {
hideSystemUi()
}
2022-09-23 12:09:22 +02:00
})
binding.rotateButton.setOnClickListener {
requestedOrientation =
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
2020-07-17 16:35:39 +02:00
}
2021-03-17 21:11:14 +01:00
2022-03-05 19:23:48 +01:00
override fun onNewFileName(fileName: String) {
binding.textFileName.text = fileName
}
2021-03-17 21:11:14 +01:00
override fun getFileType(): String {
return "video"
}
2021-04-05 12:42:35 +02:00
2021-12-21 10:50:26 +01:00
override fun onVideoSizeChanged(width: Int, height: Int) {
2021-04-05 12:42:35 +02:00
if (firstPlay && autoFit) {
2021-12-21 10:50:26 +01:00
requestedOrientation = if (width < height)
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
else
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
2021-04-05 12:42:35 +02:00
firstPlay = false
}
}
2020-07-17 16:35:39 +02:00
}