mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #2101 from Kruna1Pate1/fix/pip-aspect-ratio
Fix to adopt dynamic aspect ration in PiP mode
This commit is contained in:
commit
dbf4002e62
@ -0,0 +1,22 @@
|
||||
package com.github.libretube.ui.extensions
|
||||
|
||||
import android.app.PictureInPictureParams
|
||||
import android.os.Build
|
||||
import android.util.Rational
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun PictureInPictureParams.Builder.setAspectRatio(
|
||||
width: Int,
|
||||
height: Int
|
||||
): PictureInPictureParams.Builder {
|
||||
val ratio = (width.toFloat() / height).let {
|
||||
when {
|
||||
it.isNaN() -> Rational(4, 3)
|
||||
it <= 0.418410 -> Rational(41841, 100000)
|
||||
it >= 2.390000 -> Rational(239, 100)
|
||||
else -> Rational(width, height)
|
||||
}
|
||||
}
|
||||
return setAspectRatio(ratio)
|
||||
}
|
@ -71,6 +71,7 @@ import com.github.libretube.ui.base.BaseFragment
|
||||
import com.github.libretube.ui.dialogs.AddToPlaylistDialog
|
||||
import com.github.libretube.ui.dialogs.DownloadDialog
|
||||
import com.github.libretube.ui.dialogs.ShareDialog
|
||||
import com.github.libretube.ui.extensions.setAspectRatio
|
||||
import com.github.libretube.ui.extensions.setFormattedHtml
|
||||
import com.github.libretube.ui.extensions.setInvisible
|
||||
import com.github.libretube.ui.extensions.setupSubscriptionButton
|
||||
@ -277,7 +278,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
binding.playerMotionLayout.transitionToStart()
|
||||
}
|
||||
|
||||
if (usePiP()) (activity as MainActivity).setPictureInPictureParams(getPipParams())
|
||||
if (usePiP()) activity?.setPictureInPictureParams(getPipParams())
|
||||
|
||||
if (SDK_INT < Build.VERSION_CODES.O) {
|
||||
binding.relPlayerPip.visibility = View.GONE
|
||||
@ -823,6 +824,8 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
// media actually playing
|
||||
transitioning = false
|
||||
binding.playImageView.setImageResource(R.drawable.ic_pause)
|
||||
// update the PiP params to use the correct aspect ratio
|
||||
if (usePiP()) activity?.setPictureInPictureParams(getPipParams())
|
||||
}
|
||||
Player.STATE_ENDED -> {
|
||||
// video has finished
|
||||
@ -1360,6 +1363,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
if (SDK_INT >= Build.VERSION_CODES.S) {
|
||||
setAutoEnterEnabled(true)
|
||||
}
|
||||
if (exoPlayer.isPlaying) {
|
||||
setAspectRatio(exoPlayer.videoSize.width, exoPlayer.videoSize.height)
|
||||
}
|
||||
}
|
||||
.build()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user