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
|
2022-05-07 14:51:20 +02:00
|
|
|
import android.content.res.Configuration
|
2023-03-13 17:02:38 +01:00
|
|
|
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
|
|
|
|
2020-07-26 21:16:06 +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)
|
2023-03-13 17:02:38 +01:00
|
|
|
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
|
2023-03-13 17:02:38 +01:00
|
|
|
if (visibility == View.VISIBLE) {
|
|
|
|
showPartialSystemUi()
|
|
|
|
} else {
|
|
|
|
hideSystemUi()
|
|
|
|
}
|
2022-09-23 12:09:22 +02:00
|
|
|
})
|
2021-12-15 09:13:30 +01:00
|
|
|
binding.rotateButton.setOnClickListener {
|
|
|
|
requestedOrientation =
|
2022-05-07 14:51:20 +02:00
|
|
|
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
|
|
|
} else {
|
2021-12-15 09:13:30 +01:00
|
|
|
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
2022-05-07 14:51:20 +02:00
|
|
|
}
|
2021-12-15 09:13:30 +01:00
|
|
|
}
|
2022-05-07 14:51:20 +02:00
|
|
|
super.viewFile()
|
|
|
|
}
|
2021-12-15 09:13:30 +01:00
|
|
|
|
2022-05-07 14:51:20 +02:00
|
|
|
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
|
|
|
}
|