Option for auto fullscreen on shorts

This commit is contained in:
Bnyro 2023-03-24 16:02:56 +01:00
parent 158185a010
commit 11dc261f91
7 changed files with 31 additions and 8 deletions

View File

@ -94,6 +94,7 @@ object PreferenceKeys {
const val ENABLED_VIDEO_CODECS = "video_codecs"
const val AUTOPLAY_COUNTDOWN = "autoplay_countdown"
const val LBRY_HLS = "lbry_hls"
const val AUTO_FULLSCREEN_SHORTS = "auto_fullscreen_shorts"
/**
* Background mode

View File

@ -25,7 +25,6 @@ import com.google.android.exoplayer2.LoadControl
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ui.CaptionStyleCompat
import com.google.android.exoplayer2.video.VideoSize
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
@ -152,7 +151,7 @@ object PlayerHelper {
return categories
}
fun getOrientation(videoSize: VideoSize): Int {
fun getOrientation(videoWidth: Int, videoHeight: Int): Int {
val fullscreenOrientationPref = PreferenceHelper.getString(
PreferenceKeys.FULLSCREEN_ORIENTATION,
"ratio"
@ -161,7 +160,7 @@ object PlayerHelper {
return when (fullscreenOrientationPref) {
"ratio" -> {
// probably a youtube shorts video
if (videoSize.height > videoSize.width) {
if (videoHeight > videoWidth) {
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
} // a video with normal aspect ratio
else {

View File

@ -63,7 +63,10 @@ class OfflinePlayerActivity : BaseActivity() {
initializePlayer()
playVideo()
requestedOrientation = PlayerHelper.getOrientation(player.videoSize)
requestedOrientation = PlayerHelper.getOrientation(
player.videoSize.width,
player.videoSize.height
)
}
private fun initializePlayer() {

View File

@ -494,8 +494,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerBinding.exoTitle.visibility = View.VISIBLE
if (!PlayerHelper.autoRotationEnabled) {
val height = streams.videoStreams.firstOrNull()?.height ?: exoPlayer.videoSize.height
val width = streams.videoStreams.firstOrNull()?.width ?: exoPlayer.videoSize.width
// different orientations of the video are only available when auto rotation is disabled
val orientation = PlayerHelper.getOrientation(exoPlayer.videoSize)
val orientation = PlayerHelper.getOrientation(width, height)
mainActivity.requestedOrientation = orientation
}
@ -685,6 +688,17 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
PlayingQueue.updateCurrent(streams.toStreamItem(videoId!!))
}
if (PreferenceHelper.getBoolean(PreferenceKeys.AUTO_FULLSCREEN_SHORTS, false)) {
val videoStream = streams.videoStreams.firstOrNull()
if (PlayingQueue.getCurrent()?.isShort == true ||
(videoStream?.height ?: 0) > (videoStream?.width ?: 0)
) {
withContext(Dispatchers.Main) {
setFullscreen()
}
}
}
PlayingQueue.setOnQueueTapListener { streamItem ->
streamItem.url?.toID()?.let { playNextVideo(it) }
}

View File

@ -583,8 +583,8 @@ internal class CustomExoPlayerView(
super.onConfigurationChanged(newConfig)
// add a larger bottom margin to the time bar in landscape mode
val offset = when (newConfig?.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> 20.dpToPx()
val offset = when {
playerViewModel?.isFullscreen?.value ?: (newConfig?.orientation == Configuration.ORIENTATION_LANDSCAPE) -> 20.dpToPx()
else -> 10.dpToPx()
}

View File

@ -455,7 +455,7 @@
<string name="lbry_hls_summary">Use LBRY HLS for streaming if available.</string>
<string name="disable_proxy">Disable Piped proxy</string>
<string name="disable_proxy_summary">Load videos and images directly from YouTube\'s servers. Only enable the option if you use a VPN anyways! Note that this might not work with content from YT music.</string>
<string name="auto_fullscreen_shorts">Auto fullscreen on short videos</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>

View File

@ -166,6 +166,12 @@
app:key="autoplay_countdown"
app:title="@string/autoplay_countdown" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_fullscreen"
android:title="@string/auto_fullscreen_shorts"
app:key="auto_fullscreen_shorts" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/background_mode">