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
|
2020-07-26 21:16:06 +02:00
|
|
|
import com.google.android.exoplayer2.SimpleExoPlayer
|
2020-07-17 16:35:39 +02:00
|
|
|
import kotlinx.android.synthetic.main.activity_video_player.*
|
|
|
|
import sushi.hardcore.droidfs.R
|
|
|
|
|
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)
|
|
|
|
}
|
2020-07-17 16:35:39 +02:00
|
|
|
override fun viewFile() {
|
|
|
|
setContentView(R.layout.activity_video_player)
|
2020-08-08 14:09:34 +02:00
|
|
|
super.viewFile()
|
2020-07-26 21:16:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun bindPlayer(player: SimpleExoPlayer) {
|
|
|
|
video_player.player = player
|
2020-07-17 16:35:39 +02:00
|
|
|
}
|
2021-03-17 21:11:14 +01:00
|
|
|
|
|
|
|
override fun getFileType(): String {
|
|
|
|
return "video"
|
|
|
|
}
|
2021-04-05 12:42:35 +02:00
|
|
|
|
|
|
|
override fun onPlayerReady() {
|
|
|
|
if (firstPlay && autoFit) {
|
|
|
|
requestedOrientation = if (video_player.width < video_player.height) ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
|
|
|
firstPlay = false
|
|
|
|
}
|
|
|
|
}
|
2020-07-17 16:35:39 +02:00
|
|
|
}
|