Fix PiP aspect ratio in offline player

This commit is contained in:
Krunal Patel 2022-11-28 11:56:12 +05:30
parent fe02b0e30c
commit 4c3060c17f
2 changed files with 9 additions and 3 deletions

View File

@ -17,6 +17,7 @@ import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.ActivityOfflinePlayerBinding import com.github.libretube.databinding.ActivityOfflinePlayerBinding
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setAspectRatio
import com.github.libretube.ui.models.PlayerViewModel import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.util.DownloadHelper import com.github.libretube.util.DownloadHelper
import com.github.libretube.util.PlayerHelper import com.github.libretube.util.PlayerHelper
@ -182,6 +183,7 @@ class OfflinePlayerActivity : BaseActivity() {
enterPictureInPictureMode( enterPictureInPictureMode(
PictureInPictureParams.Builder() PictureInPictureParams.Builder()
.setActions(emptyList()) .setActions(emptyList())
.setAspectRatio(player.videoSize.width, player.videoSize.height)
.build() .build()
) )

View File

@ -18,15 +18,18 @@ import kotlin.math.abs
class PlayerGestureController(activity: BaseActivity, private val listener: PlayerGestureOptions) : class PlayerGestureController(activity: BaseActivity, private val listener: PlayerGestureOptions) :
View.OnTouchListener { View.OnTouchListener {
// width and height should be obtained each time using getter to adopt layout size changes. // width and height should be obtained each time using getter to adopt layout
// size changes.
private val width get() = Resources.getSystem().displayMetrics.widthPixels private val width get() = Resources.getSystem().displayMetrics.widthPixels
private val height get() = Resources.getSystem().displayMetrics.heightPixels private val height get() = Resources.getSystem().displayMetrics.heightPixels
private val elapsedTime get() = SystemClock.elapsedRealtime() private val elapsedTime get() = SystemClock.elapsedRealtime()
private val playerViewModel: PlayerViewModel by activity.viewModels()
private val playerViewModel: PlayerViewModel by activity.viewModels()
private val handler: Handler = Handler(Looper.getMainLooper()) private val handler: Handler = Handler(Looper.getMainLooper())
private val gestureDetector: GestureDetector private val gestureDetector: GestureDetector
private val scaleGestureDetector: ScaleGestureDetector private val scaleGestureDetector: ScaleGestureDetector
private var isFullscreen = false private var isFullscreen = false
private var isMoving = false private var isMoving = false
var isEnabled = true var isEnabled = true
@ -54,7 +57,8 @@ class PlayerGestureController(activity: BaseActivity, private val listener: Play
gestureDetector.onTouchEvent(event) gestureDetector.onTouchEvent(event)
} catch (_: Exception) { } } catch (_: Exception) { }
// If video is playing in full-screen then allow `onScroll` to consume event and return true. // If video is playing in full-screen mode, then allow `onScroll` to consume
// event and return true.
return isFullscreen return isFullscreen
} }