mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Option for auto fullscreen on shorts
This commit is contained in:
parent
158185a010
commit
11dc261f91
@ -94,6 +94,7 @@ object PreferenceKeys {
|
|||||||
const val ENABLED_VIDEO_CODECS = "video_codecs"
|
const val ENABLED_VIDEO_CODECS = "video_codecs"
|
||||||
const val AUTOPLAY_COUNTDOWN = "autoplay_countdown"
|
const val AUTOPLAY_COUNTDOWN = "autoplay_countdown"
|
||||||
const val LBRY_HLS = "lbry_hls"
|
const val LBRY_HLS = "lbry_hls"
|
||||||
|
const val AUTO_FULLSCREEN_SHORTS = "auto_fullscreen_shorts"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background mode
|
* Background mode
|
||||||
|
@ -25,7 +25,6 @@ import com.google.android.exoplayer2.LoadControl
|
|||||||
import com.google.android.exoplayer2.PlaybackParameters
|
import com.google.android.exoplayer2.PlaybackParameters
|
||||||
import com.google.android.exoplayer2.audio.AudioAttributes
|
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||||
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
import com.google.android.exoplayer2.ui.CaptionStyleCompat
|
||||||
import com.google.android.exoplayer2.video.VideoSize
|
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@ -152,7 +151,7 @@ object PlayerHelper {
|
|||||||
return categories
|
return categories
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getOrientation(videoSize: VideoSize): Int {
|
fun getOrientation(videoWidth: Int, videoHeight: Int): Int {
|
||||||
val fullscreenOrientationPref = PreferenceHelper.getString(
|
val fullscreenOrientationPref = PreferenceHelper.getString(
|
||||||
PreferenceKeys.FULLSCREEN_ORIENTATION,
|
PreferenceKeys.FULLSCREEN_ORIENTATION,
|
||||||
"ratio"
|
"ratio"
|
||||||
@ -161,7 +160,7 @@ object PlayerHelper {
|
|||||||
return when (fullscreenOrientationPref) {
|
return when (fullscreenOrientationPref) {
|
||||||
"ratio" -> {
|
"ratio" -> {
|
||||||
// probably a youtube shorts video
|
// probably a youtube shorts video
|
||||||
if (videoSize.height > videoSize.width) {
|
if (videoHeight > videoWidth) {
|
||||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||||
} // a video with normal aspect ratio
|
} // a video with normal aspect ratio
|
||||||
else {
|
else {
|
||||||
|
@ -63,7 +63,10 @@ class OfflinePlayerActivity : BaseActivity() {
|
|||||||
initializePlayer()
|
initializePlayer()
|
||||||
playVideo()
|
playVideo()
|
||||||
|
|
||||||
requestedOrientation = PlayerHelper.getOrientation(player.videoSize)
|
requestedOrientation = PlayerHelper.getOrientation(
|
||||||
|
player.videoSize.width,
|
||||||
|
player.videoSize.height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializePlayer() {
|
private fun initializePlayer() {
|
||||||
|
@ -494,8 +494,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
playerBinding.exoTitle.visibility = View.VISIBLE
|
playerBinding.exoTitle.visibility = View.VISIBLE
|
||||||
|
|
||||||
if (!PlayerHelper.autoRotationEnabled) {
|
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
|
// 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
|
mainActivity.requestedOrientation = orientation
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,6 +688,17 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
PlayingQueue.updateCurrent(streams.toStreamItem(videoId!!))
|
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 ->
|
PlayingQueue.setOnQueueTapListener { streamItem ->
|
||||||
streamItem.url?.toID()?.let { playNextVideo(it) }
|
streamItem.url?.toID()?.let { playNextVideo(it) }
|
||||||
}
|
}
|
||||||
|
@ -583,8 +583,8 @@ internal class CustomExoPlayerView(
|
|||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
// add a larger bottom margin to the time bar in landscape mode
|
// add a larger bottom margin to the time bar in landscape mode
|
||||||
val offset = when (newConfig?.orientation) {
|
val offset = when {
|
||||||
Configuration.ORIENTATION_LANDSCAPE -> 20.dpToPx()
|
playerViewModel?.isFullscreen?.value ?: (newConfig?.orientation == Configuration.ORIENTATION_LANDSCAPE) -> 20.dpToPx()
|
||||||
else -> 10.dpToPx()
|
else -> 10.dpToPx()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +455,7 @@
|
|||||||
<string name="lbry_hls_summary">Use LBRY HLS for streaming if available.</string>
|
<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">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="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 -->
|
<!-- Notification channel strings -->
|
||||||
<string name="download_channel_name">Download Service</string>
|
<string name="download_channel_name">Download Service</string>
|
||||||
|
@ -166,6 +166,12 @@
|
|||||||
app:key="autoplay_countdown"
|
app:key="autoplay_countdown"
|
||||||
app:title="@string/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>
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/background_mode">
|
<PreferenceCategory app:title="@string/background_mode">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user