video aspect ratio & lifecycle changes

This commit is contained in:
jmir1 2022-01-15 12:57:04 +01:00
parent ab6128e1f5
commit f58df8262d
5 changed files with 44 additions and 11 deletions

View file

@ -114,6 +114,7 @@
<activity
android:name=".ui.player.NewPlayerActivity"
android:launchMode="singleTask"
android:screenOrientation="userLandscape"
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize|keyboardHidden|keyboard"
android:supportsPictureInPicture="true"
android:resizeableActivity="true"

View file

@ -131,6 +131,8 @@ class PreferencesHelper(val context: Context) {
fun getPlayerViewMode() = prefs.getInt(Keys.playerViewMode, 0)
fun playerFullscreen() = prefs.getBoolean("player_fullscreen", true)
fun setPlayerViewMode(newMode: Int) = prefs.edit {
putInt(Keys.playerViewMode, newMode)
}

View file

@ -73,6 +73,8 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
private var playerViewMode: Int = preferences.getPlayerViewMode()
private var playerIsDestroyed = true
@RequiresApi(Build.VERSION_CODES.P)
override fun onCreate(savedInstanceState: Bundle?) {
logcat { "bruh" }
@ -104,20 +106,24 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
presenter.init(anime, episode)
}
setViewMode()
playerIsDestroyed = false
}
private fun setViewMode() {
when (playerViewMode) {
2 -> {
MPVLib.setOptionString("keepaspect", "yes")
MPVLib.setOptionString("video-aspect-override", "-1")
MPVLib.setOptionString("panscan", "1.0")
}
1 -> {
MPVLib.setOptionString("keepaspect", "yes")
MPVLib.setOptionString("video-aspect-override", "-1")
MPVLib.setOptionString("panscan", "0.0")
}
0 -> {
val newAspect = "${binding.root.width}/${binding.root.height}"
MPVLib.setOptionString("video-aspect-override", newAspect)
MPVLib.setOptionString("panscan", "0.0")
}
0 -> MPVLib.setOptionString("keepaspect", "no")
}
}
@ -131,7 +137,7 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && preferences.playerFullscreen()) {
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
}
@ -264,9 +270,18 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
player.timePos?.let { updatePlaybackPos(it) }
player.duration?.let { updatePlaybackDuration(it) }
updatePlaylistButtons()
updateEpisodeText()
player.loadTracks()
}
private fun updateEpisodeText() {
binding.fullTitleTextView.text = applicationContext.getString(
R.string.playertitle,
presenter.anime?.title,
presenter.currentEpisode?.name
)
}
private fun updatePlaylistButtons() {
val plCount = presenter.episodeList.size
val plPos = presenter.getCurrentEpisodeIndex()
@ -298,8 +313,16 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
}
override fun onDestroy() {
player.destroy()
super.onDestroy()
if (!playerIsDestroyed) {
player.destroy()
playerIsDestroyed = true
}
}
override fun onStop() {
if (!playerIsDestroyed) player.paused = true
super.onStop()
}
/**
@ -313,6 +336,7 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
}
fun setVideoList(videos: List<Video>?, videoPos: Int = 0, timePos: Int? = null) {
if (playerIsDestroyed) return
logcat(LogPriority.INFO) { "loaded!!" }
currentVideoList = videos ?: currentVideoList
currentVideoList?.getOrNull(videoPos)?.videoUrl.let {
@ -322,6 +346,7 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
val intPos = pos / 1000F
MPVLib.command(arrayOf("set", "start", "$intPos"))
}
setViewMode()
MPVLib.command(arrayOf("loadfile", it))
}
launchUI { refreshUi() }
@ -366,9 +391,4 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
override fun eventProperty(property: String, value: String) {}
override fun event(eventId: Int) {}
override fun onStop() {
player.paused = true
super.onStop()
}
}

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.setting
import android.os.Build
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.preference.defaultValue
@ -63,6 +64,14 @@ class SettingsPlayerController : SettingsController() {
summary = "%s"
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
switchPreference {
key = "player_fullscreen"
titleRes = R.string.pref_player_fullscreen
defaultValue = true
}
}
switchPreference {
key = Keys.alwaysUseExternalPlayer
titleRes = R.string.pref_always_use_external_player

View file

@ -433,6 +433,7 @@
<string name="pref_pip_player">Enable picture in picture mode</string>
<string name="pref_pip_player_summary">Note: this is still an experimental feature!</string>
<string name="pref_always_use_external_player">Always use external player</string>
<string name="pref_player_fullscreen">Show content in display cutout</string>
<string name="pref_external_player_preference">External player preference</string>
<string name="pref_progress_70">70%</string>
<string name="pref_progress_75">75%</string>