mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-25 22:29:45 +03:00
video aspect ratio & lifecycle changes
This commit is contained in:
parent
ab6128e1f5
commit
f58df8262d
5 changed files with 44 additions and 11 deletions
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue