diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt index 431191a18..d13cefcee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/anime/AnimeController.kt @@ -881,7 +881,7 @@ class AnimeController : duration = data.getLongExtra("extra_duration", 0L) } else { currentPosition = data.getIntExtra("position", 0).toLong() - duration = 1440000L + duration = data.getIntExtra("duration", 0).toLong() } } if (cause == "playback_completion") { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/player/NewPlayerActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/player/NewPlayerActivity.kt index c7889e5d4..d871545e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/player/NewPlayerActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/player/NewPlayerActivity.kt @@ -11,6 +11,7 @@ import android.widget.SeekBar import androidx.annotation.RequiresApi import androidx.core.content.ContextCompat import androidx.core.view.isVisible +import com.google.android.material.dialog.MaterialAlertDialogBuilder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.animesource.model.Video import eu.kanade.tachiyomi.data.database.models.Anime @@ -19,6 +20,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.NewPlayerActivityBinding import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity.Companion.applyAppTheme +import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.toast import `is`.xyz.mpv.MPVLib @@ -27,7 +29,6 @@ import logcat.LogPriority import nucleus.factory.RequiresPresenter import uy.kohesive.injekt.injectLazy import java.io.File -import kotlin.math.abs @RequiresPresenter(NewPlayerPresenter::class) class NewPlayerActivity : BaseRxActivity(), MPVLib.EventObserver { @@ -70,6 +71,8 @@ class NewPlayerActivity : BaseRxActivity? = null + private var playerViewMode: Int = preferences.getPlayerViewMode() + @RequiresApi(Build.VERSION_CODES.P) override fun onCreate(savedInstanceState: Bundle?) { logcat { "bruh" } @@ -100,6 +103,22 @@ class NewPlayerActivity : BaseRxActivity { + MPVLib.setOptionString("keepaspect", "yes") + MPVLib.setOptionString("panscan", "1.0") + } + 1 -> { + MPVLib.setOptionString("keepaspect", "yes") + MPVLib.setOptionString("panscan", "0.0") + } + 0 -> MPVLib.setOptionString("keepaspect", "no") + } } @Suppress("DEPRECATION") @@ -118,7 +137,7 @@ class NewPlayerActivity : BaseRxActivity 1 + 1 -> 2 + 2 -> 0 + else -> 1 + } + preferences.setPlayerViewMode(playerViewMode) + setViewMode() + } + + private var currentQuality = 0 + + @Suppress("UNUSED_PARAMETER") + fun openSettings(view: View) { + if (currentVideoList?.isNotEmpty() == true) { + val qualityAlert = MaterialAlertDialogBuilder(this) + + qualityAlert.setTitle(R.string.playback_quality_dialog_title) + + var requestedQuality = 0 + val qualities = currentVideoList!!.map { it.quality }.toTypedArray() + qualityAlert.setSingleChoiceItems(qualities, currentQuality) { qualityDialog, selectedQuality -> + if (selectedQuality > qualities.lastIndex) { + qualityDialog.cancel() + } else { + requestedQuality = selectedQuality + } + } + + qualityAlert.setPositiveButton(android.R.string.ok) { qualityDialog, _ -> + if (requestedQuality != currentQuality) changeQuality(requestedQuality) + qualityDialog.dismiss() + } + + qualityAlert.setNegativeButton(android.R.string.cancel) { qualityDialog, _ -> + qualityDialog.cancel() + } + + qualityAlert.show() + } + } + + private fun changeQuality(quality: Int) { + setVideoList(null, quality, player.timePos) + } + @Suppress("UNUSED_PARAMETER") fun switchDecoder(view: View) { player.cycleHwdec() + preferences.getPlayerViewMode() updateDecoderButton() } @@ -203,8 +271,6 @@ class NewPlayerActivity : BaseRxActivity) { + fun setVideoList(videos: List